From 887a5256e5e5aab1daf8ee82606920459936b8d9 Mon Sep 17 00:00:00 2001 From: JuArce Date: Mon, 5 Feb 2024 11:00:01 -0300 Subject: [PATCH] test: remove escrow_cancel tests --- contracts/cairo/src/lib.cairo | 1 - .../cairo/src/tests/test_escrow_cancel.cairo | 145 ------------------ 2 files changed, 146 deletions(-) delete mode 100644 contracts/cairo/src/tests/test_escrow_cancel.cairo diff --git a/contracts/cairo/src/lib.cairo b/contracts/cairo/src/lib.cairo index a7188ff1..87cce74f 100644 --- a/contracts/cairo/src/lib.cairo +++ b/contracts/cairo/src/lib.cairo @@ -16,7 +16,6 @@ mod mocks { #[cfg(test)] mod tests { mod test_escrow_allowance; - mod test_escrow_cancel; mod test_escrow_pause; mod test_escrow_upgrade; mod test_escrow_ownable; diff --git a/contracts/cairo/src/tests/test_escrow_cancel.cairo b/contracts/cairo/src/tests/test_escrow_cancel.cairo deleted file mode 100644 index 532260bd..00000000 --- a/contracts/cairo/src/tests/test_escrow_cancel.cairo +++ /dev/null @@ -1,145 +0,0 @@ -mod Escrow { - use core::to_byte_array::FormatAsByteArray; - use core::serde::Serde; - use core::traits::Into; - use starknet::{EthAddress, ContractAddress}; - use integer::BoundedInt; - - use snforge_std::{declare, ContractClassTrait, L1Handler, L1HandlerTrait}; - use snforge_std::{CheatTarget, start_prank, stop_prank, start_warp, stop_warp}; - - use yab::mocks::mock_Escrow_changed_functions::{IEscrow_mock_changed_functionsDispatcher, IEscrow_mock_changed_functionsDispatcherTrait}; - use yab::mocks::mock_pausableEscrow::{IEscrow_mockPausableDispatcher, IEscrow_mockPausableDispatcherTrait}; - use yab::interfaces::IERC20::{IERC20Dispatcher, IERC20DispatcherTrait}; - use yab::escrow::{IEscrowDispatcher, IEscrowDispatcherTrait, Order}; - use yab::interfaces::IEVMFactsRegistry::{ - IEVMFactsRegistryDispatcher, IEVMFactsRegistryDispatcherTrait - }; - - use yab::tests::utils::{ - constants::EscrowConstants::{ - USER, OWNER, MM_STARKNET, MM_ETHEREUM, ETH_TRANSFER_CONTRACT, ETH_USER - }, - }; - - use openzeppelin::{ - upgrades::{ - UpgradeableComponent, - interface::{IUpgradeable, IUpgradeableDispatcher, IUpgradeableDispatcherTrait} - }, - }; - - fn setup() -> (IEscrowDispatcher, IERC20Dispatcher) { - setup_general(BoundedInt::max(), BoundedInt::max()) - } - - fn setup_approved(approved: u256) -> (IEscrowDispatcher, IERC20Dispatcher){ - setup_general(BoundedInt::max(), approved) - } - - fn setup_balance(balance: u256) -> (IEscrowDispatcher, IERC20Dispatcher){ - setup_general(balance, BoundedInt::max()) - } - - fn setup_general(balance: u256, approved: u256) -> (IEscrowDispatcher, IERC20Dispatcher){ - let eth_token = deploy_erc20('ETH', '$ETH', BoundedInt::max(), OWNER()); - let escrow = deploy_escrow( - OWNER(), - ETH_TRANSFER_CONTRACT(), - MM_ETHEREUM(), - MM_STARKNET(), - eth_token.contract_address - ); - - start_prank(CheatTarget::One(eth_token.contract_address), OWNER()); - eth_token.transfer(USER(), balance); - stop_prank(CheatTarget::One(eth_token.contract_address)); - - start_prank(CheatTarget::One(eth_token.contract_address), USER()); - eth_token.approve(escrow.contract_address, approved); - stop_prank(CheatTarget::One(eth_token.contract_address)); - - (escrow, eth_token) - } - - fn deploy_escrow( - escrow_owner: ContractAddress, - eth_transfer_contract: EthAddress, - mm_ethereum_contract: EthAddress, - mm_starknet_contract: ContractAddress, - native_token_eth_starknet: ContractAddress - ) -> IEscrowDispatcher { - let escrow = declare('Escrow'); - let mut calldata: Array = ArrayTrait::new(); - calldata.append(escrow_owner.into()); - calldata.append(eth_transfer_contract.into()); - calldata.append(mm_ethereum_contract.into()); - calldata.append(mm_starknet_contract.into()); - calldata.append(native_token_eth_starknet.into()); - let address = escrow.deploy(@calldata).unwrap(); - return IEscrowDispatcher { contract_address: address }; - } - - fn deploy_erc20( - name: felt252, symbol: felt252, initial_supply: u256, recipent: ContractAddress - ) -> IERC20Dispatcher { - let erc20 = declare('ERC20'); - let mut calldata = array![name, symbol]; - Serde::serialize(@initial_supply, ref calldata); - calldata.append(recipent.into()); - let address = erc20.deploy(@calldata).unwrap(); - return IERC20Dispatcher { contract_address: address }; - } - - #[test] - fn test_cancel_order() { - let (escrow, eth_token) = setup_balance(500); - - start_prank(CheatTarget::One(escrow.contract_address), USER()); - let order = Order { recipient_address: 12345.try_into().unwrap(), amount: 500, fee: 0 }; - let order_id = escrow.set_order(order); - - // check balance - assert(eth_token.balanceOf(escrow.contract_address) == 500, 'set_order: wrong balance '); - assert(eth_token.balanceOf(MM_STARKNET()) == 0, 'set_order: wrong balance'); - assert(eth_token.balanceOf(USER()) == 0, 'set_order: wrong allowance'); - - start_warp(CheatTarget::One(escrow.contract_address), 43201); - escrow.cancel_order(order_id); - stop_warp(CheatTarget::One(escrow.contract_address)); - - stop_prank(CheatTarget::One(escrow.contract_address)); - - // check balance - assert(eth_token.balanceOf(escrow.contract_address) == 0, 'cancel_order: wrong balance '); - assert(eth_token.balanceOf(MM_STARKNET()) == 0, 'cancel_order: wrong balance'); - assert(eth_token.balanceOf(USER()) == 500, 'cancel_order: wrong allowance'); - } - - #[test] - #[should_panic(expected: ('Not enough time has passed',))] - fn test_cancel_order_fail_time() { - let (escrow, eth_token) = setup_balance(500); - - start_prank(CheatTarget::One(escrow.contract_address), USER()); - let order = Order { recipient_address: 12345.try_into().unwrap(), amount: 500, fee: 0 }; - let order_id = escrow.set_order(order); - - escrow.cancel_order(order_id); - stop_prank(CheatTarget::One(escrow.contract_address)); - } - - #[test] - #[should_panic(expected: ('Only sender allowed',))] - fn test_cancel_order_fail_sender() { - let (escrow, eth_token) = setup_balance(500); - - start_prank(CheatTarget::One(escrow.contract_address), USER()); - let order = Order { recipient_address: 12345.try_into().unwrap(), amount: 500, fee: 0 }; - let order_id = escrow.set_order(order); - - start_warp(CheatTarget::One(escrow.contract_address), 43201); - start_prank(CheatTarget::One(escrow.contract_address), MM_STARKNET()); - escrow.cancel_order(order_id); - } -}