|
1 | | -use crate::Orderbook; |
| 1 | +use crate::{ |
| 2 | + Orderbook, |
| 3 | + test::utils::{ |
| 4 | + check_private_balance, check_public_balance, mint_to_private, setup_orderbook_with_tokens, |
| 5 | + }, |
| 6 | +}; |
2 | 7 | use aztec::{ |
3 | 8 | protocol_types::{address::AztecAddress, traits::FromField}, |
4 | | - test::helpers::{ |
5 | | - authwit::add_private_authwit_from_call_interface, test_environment::TestEnvironment, |
6 | | - }, |
| 9 | + test::helpers::authwit::add_private_authwit_from_call_interface, |
7 | 10 | }; |
8 | 11 | use token::Token; |
9 | 12 | use uint_note::uint_note::PartialUintNote; |
10 | 13 |
|
11 | | -// Utility function to setup two token contracts |
12 | | -unconstrained fn setup_tokens( |
13 | | - env: &mut TestEnvironment, |
14 | | - owner: AztecAddress, |
15 | | -) -> (AztecAddress, AztecAddress) { |
16 | | - // Deploy first token contract |
17 | | - let token0_initializer = Token::interface().constructor( |
18 | | - owner, |
19 | | - "Token00000000000000000000000000", |
20 | | - "TK00000000000000000000000000000", |
21 | | - 18, |
22 | | - ); |
23 | | - let token0_address = |
24 | | - env.deploy("@token_contract/Token").with_public_initializer(owner, token0_initializer); |
25 | | - |
26 | | - // Deploy second token contract |
27 | | - let token1_initializer = Token::interface().constructor( |
28 | | - owner, |
29 | | - "Token11111111111111111111111111", |
30 | | - "TK11111111111111111111111111111", |
31 | | - 18, |
32 | | - ); |
33 | | - let token1_address = |
34 | | - env.deploy("@token_contract/Token").with_public_initializer(owner, token1_initializer); |
35 | | - |
36 | | - (token0_address, token1_address) |
37 | | -} |
38 | | - |
39 | | -// Utility function to setup orderbook with two tokens |
40 | | -unconstrained fn setup_orderbook_with_tokens( |
41 | | - with_account_contracts: bool, |
42 | | -) -> (TestEnvironment, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress) { |
43 | | - let mut env = TestEnvironment::new(); |
44 | | - let owner = if with_account_contracts { |
45 | | - env.create_contract_account() |
46 | | - } else { |
47 | | - env.create_light_account() |
48 | | - }; |
49 | | - |
50 | | - let (token0_address, token1_address) = setup_tokens(&mut env, owner); |
51 | | - |
52 | | - // Deploy orderbook contract |
53 | | - let orderbook_initializer = Orderbook::interface().constructor(token0_address, token1_address); |
54 | | - let orderbook_address = |
55 | | - env.deploy("Orderbook").with_public_initializer(owner, orderbook_initializer); |
56 | | - |
57 | | - (env, orderbook_address, token0_address, token1_address, owner, owner) |
58 | | -} |
59 | | - |
60 | | -// Utility function to mint tokens to private balance |
61 | | -unconstrained fn mint_to_private( |
62 | | - env: TestEnvironment, |
63 | | - token_address: AztecAddress, |
64 | | - owner: AztecAddress, |
65 | | - to: AztecAddress, |
66 | | - amount: u128, |
67 | | -) { |
68 | | - env.call_private(owner, Token::at(token_address).mint_to_private(to, amount)); |
69 | | -} |
70 | | - |
71 | | -// Utility function to check private balance |
72 | | -unconstrained fn check_private_balance( |
73 | | - env: TestEnvironment, |
74 | | - token_address: AztecAddress, |
75 | | - address: AztecAddress, |
76 | | - expected_amount: u128, |
77 | | -) { |
78 | | - assert_eq( |
79 | | - env.simulate_utility(Token::at(token_address).balance_of_private(address)), |
80 | | - expected_amount, |
81 | | - ); |
82 | | -} |
83 | | - |
84 | | -// Utility function to check public balance |
85 | | -unconstrained fn check_public_balance( |
86 | | - env: TestEnvironment, |
87 | | - token_address: AztecAddress, |
88 | | - address: AztecAddress, |
89 | | - expected_amount: u128, |
90 | | -) { |
91 | | - assert_eq( |
92 | | - env.view_public(Token::at(token_address).balance_of_public(address)), |
93 | | - expected_amount, |
94 | | - ); |
95 | | -} |
96 | | - |
97 | 14 | // Happy path tests |
98 | 15 |
|
99 | 16 | #[test] |
|
0 commit comments