| 2483 | #[test] |
| 2484 | fn allows_insufficient_allowance_and_balance_for_presign_orders() { |
| 2485 | fn assert_allows_failed_transfer( |
| 2486 | create_error: impl Fn() -> TransferSimulationError + Send + 'static, |
| 2487 | is_expected_error: impl Fn(ValidationError) -> bool, |
| 2488 | ) { |
| 2489 | let mut order_quoter = MockOrderQuoting::new(); |
| 2490 | let mut balance_fetcher = MockBalanceFetching::new(); |
| 2491 | order_quoter |
| 2492 | .expect_find_quote() |
| 2493 | .returning(|_, _| Ok(Default::default())); |
| 2494 | balance_fetcher |
| 2495 | .expect_can_transfer() |
| 2496 | .returning(move |_, _| Err(create_error())); |
| 2497 | balance_fetcher |
| 2498 | .expect_allowance() |
| 2499 | .returning(|_, _, _| Ok(U256::ZERO)); |
| 2500 | let mut limit_order_counter = MockLimitOrderCounting::new(); |
| 2501 | limit_order_counter.expect_count().returning(|_| Ok(0u64)); |
| 2502 | let native_token = |
| 2503 | WETH9::Instance::new([0xef; 20].into(), ethrpc::mock::web3().provider); |
| 2504 | let validator = OrderValidator::new( |
| 2505 | native_token, |
| 2506 | Arc::new(order_validation::banned::Users::none()), |
| 2507 | OrderValidPeriodConfiguration::any(), |
| 2508 | false, |
| 2509 | Default::default(), |
| 2510 | HooksTrampoline::Instance::new( |
| 2511 | Address::from([0xcf; 20]), |
| 2512 | ProviderBuilder::new() |
| 2513 | .connect_mocked_client(Asserter::new()) |
| 2514 | .erased(), |
| 2515 | ), |
| 2516 | Arc::new(order_quoter), |
| 2517 | Arc::new(balance_fetcher), |
| 2518 | Arc::new(MockSignatureValidating::new()), |
| 2519 | None, |
| 2520 | Arc::new(limit_order_counter), |
| 2521 | 0, |
| 2522 | Default::default(), |
| 2523 | u64::MAX, |
| 2524 | SameTokensPolicy::Disallow, |
| 2525 | ); |
| 2526 | |
| 2527 | let order = OrderCreation { |
| 2528 | valid_to: u32::MAX, |
| 2529 | sell_token: Address::with_last_byte(1), |
| 2530 | sell_amount: alloy::primitives::U256::from(1), |
| 2531 | buy_token: Address::with_last_byte(2), |
| 2532 | buy_amount: alloy::primitives::U256::from(1), |
| 2533 | app_data: OrderCreationAppData::Full { |
| 2534 | full: "{}".to_string(), |
| 2535 | }, |
| 2536 | ..Default::default() |
| 2537 | }; |
| 2538 | |
| 2539 | for signing_scheme in [EcdsaSigningScheme::Eip712, EcdsaSigningScheme::EthSign] { |
| 2540 | let err = validator |
| 2541 | .validate_and_construct_order( |
| 2542 | order.clone().sign( |