From 8faf2afad5bd851be86314c33ce403f332dd3a99 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 31 Oct 2024 01:00:16 +0000 Subject: [PATCH] WIP --- .../contracts/amm_contract/src/main.nr | 2 +- .../contracts/amm_contract/src/test.nr | 3 +- .../amm_contract/src/test/full_flow.nr | 12 ++- .../contracts/amm_contract/src/test/utils.nr | 96 ++++++++++--------- 4 files changed, 61 insertions(+), 52 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/amm_contract/src/main.nr b/noir-projects/noir-contracts/contracts/amm_contract/src/main.nr index 60c896b4d2fa..89e0ca7a1164 100644 --- a/noir-projects/noir-contracts/contracts/amm_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/amm_contract/src/main.nr @@ -1,6 +1,6 @@ mod lib; mod state; -// mod test; +mod test; use dep::aztec::macros::aztec; diff --git a/noir-projects/noir-contracts/contracts/amm_contract/src/test.nr b/noir-projects/noir-contracts/contracts/amm_contract/src/test.nr index 94b4d0cbbd05..28ba21602e17 100644 --- a/noir-projects/noir-contracts/contracts/amm_contract/src/test.nr +++ b/noir-projects/noir-contracts/contracts/amm_contract/src/test.nr @@ -1 +1,2 @@ -mod full_flow; \ No newline at end of file +mod full_flow; +mod utils; diff --git a/noir-projects/noir-contracts/contracts/amm_contract/src/test/full_flow.nr b/noir-projects/noir-contracts/contracts/amm_contract/src/test/full_flow.nr index 9b0bbb7f978f..9ceac7558fdb 100644 --- a/noir-projects/noir-contracts/contracts/amm_contract/src/test/full_flow.nr +++ b/noir-projects/noir-contracts/contracts/amm_contract/src/test/full_flow.nr @@ -1,9 +1,13 @@ +use crate::{AMM, test::utils::setup}; +use dep::token::Token; +use dep::uint_note::uint_note::UintNote; +use aztec::prelude::AztecAddress; + #[test] unconstrained fn full_flow() { // Setup - let (env, amm_address, token0_address, token1_address, liquidity_token_address, token_admin, liquidity_provider, lp_balance_0, lp_balance_1, swapper_balance_0) = setup(); + let (env, amm_address, token0_address, token1_address, liquidity_token_address, token_admin, liquidity_provider, lp_balance_0, lp_balance_1, swapper_balance_0) = + setup(); let amm = AMM::at(amm_address); - // Now we add liquidity - -} \ No newline at end of file +} diff --git a/noir-projects/noir-contracts/contracts/amm_contract/src/test/utils.nr b/noir-projects/noir-contracts/contracts/amm_contract/src/test/utils.nr index 3ba0521b1df7..abcfb5e96a4c 100644 --- a/noir-projects/noir-contracts/contracts/amm_contract/src/test/utils.nr +++ b/noir-projects/noir-contracts/contracts/amm_contract/src/test/utils.nr @@ -1,5 +1,6 @@ -use dep::uint_note::uint_note::UintNote; +use crate::AMM; use dep::token::Token; +use dep::uint_note::uint_note::UintNote; use aztec::{ keys::getters::get_public_keys, oracle::{ @@ -11,10 +12,8 @@ use aztec::{ protocol_types::storage::map::derive_storage_slot_in_map, test::helpers::{cheatcodes, test_environment::TestEnvironment}, }; -use crate::AMM; -pub unconstrained fn setup( -) -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress, Field, Field, Field) { +pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress, Field, Field, Field) { // Setup env, generate keys let mut env = TestEnvironment::new(); @@ -26,56 +25,61 @@ pub unconstrained fn setup( env.impersonate(token_admin); // Deploy tokens to be swapped and a liquidity token - let token0 = - env.deploy_self("Token").with_public_void_initializer(Token::interface().constructor( - token_admin, - "TestToken0000000000000000000000", - "TT00000000000000000000000000000", - 18, - )); - let token0_address = token0.to_address(); + let token0_address = env + .deploy_self("Token") + .with_public_void_initializer(Token::interface().constructor( + token_admin, + "TestToken0000000000000000000000", + "TT00000000000000000000000000000", + 18, + )) + .to_address(); + let token0 = Token::at(token0_address); - let token1 = - env.deploy_self("Token").with_public_void_initializer(Token::interface().constructor( - token_admin, - "TestToken1000000000000000000000", - "TT10000000000000000000000000000", - 18, - )); - let token1_address = token1.to_address(); + let token1_address = env + .deploy_self("Token") + .with_public_void_initializer(Token::interface().constructor( + token_admin, + "TestToken1000000000000000000000", + "TT10000000000000000000000000000", + 18, + )) + .to_address(); + let token1 = Token::at(token1_address); - let liquidity_token = - env.deploy_self("Token").with_public_void_initializer(Token::interface().constructor( - token_admin, - "TestLiquidityToken0000000000000", - "TLT0000000000000000000000000000", - 18, - )); - let liquidity_token_address = liquidity_token.to_address(); + let liquidity_token_address = env + .deploy_self("Token") + .with_public_void_initializer(Token::interface().constructor( + token_admin, + "TestLiquidityToken0000000000000", + "TLT0000000000000000000000000000", + 18, + )) + .to_address(); + let liquidity_token = Token::at(liquidity_token_address); - let amm = env.deploy_self("AMM").with_public_void_initializer(AMM::interface().constructor( - token0_address, - token1_address, - liquidity_token_address, - )); - let amm_address = amm.to_address(); + let amm_address = env + .deploy_self("AMM") + .with_public_void_initializer(AMM::interface().constructor( + token0_address, + token1_address, + liquidity_token_address, + )) + .to_address(); + let amm = AMM::at(amm_address); // Now we mint both tokens to the liquidity provider and token0 to swapper let lp_balance_0 = 20000; let lp_balance_1 = 10000; let swapper_balance_0 = 5000; - token0.mint_to_private(liquidity_provider, lp_balance_0).call( - &mut env.private(), - ); - token1.mint_to_private(liquidity_provider, lp_balance_1).call( - &mut env.private(), - ); - token0.mint_private(swapper, swapper_balance_0).call( - &mut env.private(), - ); - + token0.mint_to_private(liquidity_provider, lp_balance_0).call(&mut env.private()); + token1.mint_to_private(liquidity_provider, lp_balance_1).call(&mut env.private()); + token0.mint_to_private(swapper, swapper_balance_0).call(&mut env.private()); env.advance_block_by(1); - (&mut env, amm_address, token0_address, token1_address, liquidity_token_address, token_admin, liquidity_provider, lp_balance_0, lp_balance_1, swapper_balance_0) -} \ No newline at end of file + ( + &mut env, amm_address, token0_address, token1_address, liquidity_token_address, token_admin, + liquidity_provider, lp_balance_0, lp_balance_1, swapper_balance_0, + ) +}