referrerpolicy=no-referrer-when-downgrade

snowbridge_test_utils/
mock_swap_executor.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
3
4use frame_support::pallet_prelude::DispatchError;
5use pallet_asset_conversion::Swap;
6use xcm::opaque::latest::Location;
7pub struct SwapExecutor;
8
9pub const TRIGGER_SWAP_ERROR_AMOUNT: u128 = 12345;
10
11impl<AccountId> Swap<AccountId> for SwapExecutor
12where
13	AccountId: AsRef<[u8; 32]>,
14{
15	type Balance = u128;
16	type AssetKind = Location;
17
18	fn max_path_len() -> u32 {
19		2
20	}
21
22	fn swap_exact_tokens_for_tokens(
23		_sender: AccountId,
24		_path: Vec<Self::AssetKind>,
25		amount_in: Self::Balance,
26		_amount_out_min: Option<Self::Balance>,
27		_send_to: AccountId,
28		_keep_alive: bool,
29	) -> Result<Self::Balance, DispatchError> {
30		// Special case for testing SwapError:
31		// If amount_in is exactly 12345, return an error
32		if amount_in == TRIGGER_SWAP_ERROR_AMOUNT {
33			return Err(DispatchError::Other("Swap failed for test"));
34		}
35		Ok(1_000_000_000u128)
36	}
37
38	fn swap_tokens_for_exact_tokens(
39		_sender: AccountId,
40		_path: Vec<Self::AssetKind>,
41		_amount_out: Self::Balance,
42		_amount_in_max: Option<Self::Balance>,
43		_send_to: AccountId,
44		_keep_alive: bool,
45	) -> Result<Self::Balance, DispatchError> {
46		unimplemented!()
47	}
48}