/*
* Prediction Trading REST API
*
* Place and manage prediction market orders, query positions, and transfer funds via the Prediction Trading REST API.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#![allow(unused_imports)]
use async_trait::async_trait;
use derive_builder::Builder;
use reqwest;
use rust_decimal::prelude::*;
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use std::collections::BTreeMap;
use crate::common::{
config::ConfigurationRestApi,
models::{ParamBuildError, RestApiResponse},
utils::send_request,
};
use crate::w3w_prediction::rest_api::models;
const HAS_TIME_UNIT: bool = false;
#[async_trait]
pub trait TransferApi: Send + Sync {
async fn create_inbound_transfer(
&self,
params: CreateInboundTransferParams,
) -> anyhow::Result<RestApiResponse<models::CreateInboundTransferResponse>>;
async fn create_outbound_transfer(
&self,
params: CreateOutboundTransferParams,
) -> anyhow::Result<RestApiResponse<models::CreateOutboundTransferResponse>>;
async fn query_transfer_list(
&self,
params: QueryTransferListParams,
) -> anyhow::Result<RestApiResponse<models::QueryTransferListResponse>>;
async fn query_transfer_status(
&self,
params: QueryTransferStatusParams,
) -> anyhow::Result<RestApiResponse<models::QueryTransferStatusResponse>>;
}
#[derive(Debug, Clone)]
pub struct TransferApiClient {
configuration: ConfigurationRestApi,
}
impl TransferApiClient {
pub fn new(configuration: ConfigurationRestApi) -> Self {
Self { configuration }
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CreateInboundTransferAccountTypeEnum {
#[serde(rename = "SPOT")]
Spot,
#[serde(rename = "FUNDING")]
Funding,
}
impl CreateInboundTransferAccountTypeEnum {
#[must_use]
pub fn as_str(&self) -> &'static str {
match self {
Self::Spot => "SPOT",
Self::Funding => "FUNDING",
}
}
}
impl std::str::FromStr for CreateInboundTransferAccountTypeEnum {
type Err = Box<dyn std::error::Error + Send + Sync>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"SPOT" => Ok(Self::Spot),
"FUNDING" => Ok(Self::Funding),
other => Err(format!("invalid CreateInboundTransferAccountTypeEnum: {}", other).into()),
}
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CreateOutboundTransferAccountTypeEnum {
#[serde(rename = "SPOT")]
Spot,
#[serde(rename = "FUNDING")]
Funding,
}
impl CreateOutboundTransferAccountTypeEnum {
#[must_use]
pub fn as_str(&self) -> &'static str {
match self {
Self::Spot => "SPOT",
Self::Funding => "FUNDING",
}
}
}
impl std::str::FromStr for CreateOutboundTransferAccountTypeEnum {
type Err = Box<dyn std::error::Error + Send + Sync>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"SPOT" => Ok(Self::Spot),
"FUNDING" => Ok(Self::Funding),
other => {
Err(format!("invalid CreateOutboundTransferAccountTypeEnum: {}", other).into())
}
}
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CreateOutboundTransferSourceBizEnum {
#[serde(rename = "USER_TRANSFER")]
UserTransfer,
#[serde(rename = "PREDICTION_BUY")]
PredictionBuy,
}
impl CreateOutboundTransferSourceBizEnum {
#[must_use]
pub fn as_str(&self) -> &'static str {
match self {
Self::UserTransfer => "USER_TRANSFER",
Self::PredictionBuy => "PREDICTION_BUY",
}
}
}
impl std::str::FromStr for CreateOutboundTransferSourceBizEnum {
type Err = Box<dyn std::error::Error + Send + Sync>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"USER_TRANSFER" => Ok(Self::UserTransfer),
"PREDICTION_BUY" => Ok(Self::PredictionBuy),
other => Err(format!("invalid CreateOutboundTransferSourceBizEnum: {}", other).into()),
}
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum QueryTransferListDirectionEnum {
#[serde(rename = "INBOUND")]
Inbound,
#[serde(rename = "OUTBOUND")]
Outbound,
}
impl QueryTransferListDirectionEnum {
#[must_use]
pub fn as_str(&self) -> &'static str {
match self {
Self::Inbound => "INBOUND",
Self::Outbound => "OUTBOUND",
}
}
}
impl std::str::FromStr for QueryTransferListDirectionEnum {
type Err = Box<dyn std::error::Error + Send + Sync>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"INBOUND" => Ok(Self::Inbound),
"OUTBOUND" => Ok(Self::Outbound),
other => Err(format!("invalid QueryTransferListDirectionEnum: {}", other).into()),
}
}
}
/// Request parameters for the [`create_inbound_transfer`] operation.
///
/// This struct holds all of the inputs you can pass when calling
/// [`create_inbound_transfer`](#method.create_inbound_transfer).
#[derive(Clone, Debug, Builder)]
#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
pub struct CreateInboundTransferParams {
/// Wallet ID
///
/// This field is **required.
#[builder(setter(into))]
pub wallet_id: String,
/// User's prediction wallet address
///
/// This field is **required.
#[builder(setter(into))]
pub wallet_address: String,
/// Transfer amount in wei (18 decimals). Must be > 0. Example: `1000000000000000000` = 1 USDT
///
/// This field is **required.
#[builder(setter(into))]
pub from_token_amount: String,
/// Destination CEX account. Enum: `SPOT`, `FUNDING`
///
/// This field is **required.
#[builder(setter(into))]
pub account_type: CreateInboundTransferAccountTypeEnum,
/// Source token symbol. Default `USDT`
///
/// This field is **optional.
#[builder(setter(into), default)]
pub from_token: Option<String>,
/// Destination token symbol. Default `USDT`
///
/// This field is **optional.
#[builder(setter(into), default)]
pub to_token: Option<String>,
/// Chain ID. Default `56` (BSC)
///
/// This field is **optional.
#[builder(setter(into), default)]
pub chain_id: Option<String>,
}
impl CreateInboundTransferParams {
/// Create a builder for [`create_inbound_transfer`].
///
/// Required parameters:
///
/// * `wallet_id` — Wallet ID
/// * `wallet_address` — User's prediction wallet address
/// * `from_token_amount` — Transfer amount in wei (18 decimals). Must be > 0. Example: `1000000000000000000` = 1 USDT
/// * `account_type` — Destination CEX account. Enum: `SPOT`, `FUNDING`
///
#[must_use]
pub fn builder(
wallet_id: String,
wallet_address: String,
from_token_amount: String,
account_type: CreateInboundTransferAccountTypeEnum,
) -> CreateInboundTransferParamsBuilder {
CreateInboundTransferParamsBuilder::default()
.wallet_id(wallet_id)
.wallet_address(wallet_address)
.from_token_amount(from_token_amount)
.account_type(account_type)
}
}
/// Request parameters for the [`create_outbound_transfer`] operation.
///
/// This struct holds all of the inputs you can pass when calling
/// [`create_outbound_transfer`](#method.create_outbound_transfer).
#[derive(Clone, Debug, Builder)]
#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
pub struct CreateOutboundTransferParams {
/// Wallet ID
///
/// This field is **required.
#[builder(setter(into))]
pub wallet_id: String,
/// User's prediction wallet address
///
/// This field is **required.
#[builder(setter(into))]
pub wallet_address: String,
/// Transfer amount in wei (18 decimals). Must be > 0. Example: `1000000000000000000` = 1 USDT
///
/// This field is **required.
#[builder(setter(into))]
pub from_token_amount: String,
/// Source CEX account. Enum: `SPOT`, `FUNDING`
///
/// This field is **required.
#[builder(setter(into))]
pub account_type: CreateOutboundTransferAccountTypeEnum,
/// Business source. Enum: `USER_TRANSFER`, `PREDICTION_BUY`
///
/// This field is **required.
#[builder(setter(into))]
pub source_biz: CreateOutboundTransferSourceBizEnum,
/// Source token symbol. Default `USDT`
///
/// This field is **optional.
#[builder(setter(into), default)]
pub from_token: Option<String>,
/// Destination token symbol. Default `USDT`
///
/// This field is **optional.
#[builder(setter(into), default)]
pub to_token: Option<String>,
/// Chain ID. Default `56` (BSC)
///
/// This field is **optional.
#[builder(setter(into), default)]
pub chain_id: Option<String>,
}
impl CreateOutboundTransferParams {
/// Create a builder for [`create_outbound_transfer`].
///
/// Required parameters:
///
/// * `wallet_id` — Wallet ID
/// * `wallet_address` — User's prediction wallet address
/// * `from_token_amount` — Transfer amount in wei (18 decimals). Must be > 0. Example: `1000000000000000000` = 1 USDT
/// * `account_type` — Source CEX account. Enum: `SPOT`, `FUNDING`
/// * `source_biz` — Business source. Enum: `USER_TRANSFER`, `PREDICTION_BUY`
///
#[must_use]
pub fn builder(
wallet_id: String,
wallet_address: String,
from_token_amount: String,
account_type: CreateOutboundTransferAccountTypeEnum,
source_biz: CreateOutboundTransferSourceBizEnum,
) -> CreateOutboundTransferParamsBuilder {
CreateOutboundTransferParamsBuilder::default()
.wallet_id(wallet_id)
.wallet_address(wallet_address)
.from_token_amount(from_token_amount)
.account_type(account_type)
.source_biz(source_biz)
}
}
/// Request parameters for the [`query_transfer_list`] operation.
///
/// This struct holds all of the inputs you can pass when calling
/// [`query_transfer_list`](#method.query_transfer_list).
#[derive(Clone, Debug, Builder)]
#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
pub struct QueryTransferListParams {
/// User's prediction wallet address
///
/// This field is **required.
#[builder(setter(into))]
pub wallet_address: String,
/// Start date. Format: `yyyy-MM-dd`. Must be ≤ `endDate`
///
/// This field is **required.
#[builder(setter(into))]
pub start_date: String,
/// End date. Format: `yyyy-MM-dd`. Must be ≥ `startDate`
///
/// This field is **required.
#[builder(setter(into))]
pub end_date: String,
/// Filter by token symbol (e.g. `USDT`)
///
/// This field is **optional.
#[builder(setter(into), default)]
pub token_symbol: Option<String>,
/// Filter by direction. Enum: `INBOUND`, `OUTBOUND`
///
/// This field is **optional.
#[builder(setter(into), default)]
pub direction: Option<QueryTransferListDirectionEnum>,
/// Pagination offset. Default `0`
///
/// This field is **optional.
#[builder(setter(into), default)]
pub offset: Option<i32>,
/// Page size. Default `20`, range 1–100
///
/// This field is **optional.
#[builder(setter(into), default)]
pub limit: Option<i32>,
/// Request validity window in milliseconds
///
/// This field is **optional.
#[builder(setter(into), default)]
pub recv_window: Option<i64>,
}
impl QueryTransferListParams {
/// Create a builder for [`query_transfer_list`].
///
/// Required parameters:
///
/// * `wallet_address` — User's prediction wallet address
/// * `start_date` — Start date. Format: `yyyy-MM-dd`. Must be ≤ `endDate`
/// * `end_date` — End date. Format: `yyyy-MM-dd`. Must be ≥ `startDate`
///
#[must_use]
pub fn builder(
wallet_address: String,
start_date: String,
end_date: String,
) -> QueryTransferListParamsBuilder {
QueryTransferListParamsBuilder::default()
.wallet_address(wallet_address)
.start_date(start_date)
.end_date(end_date)
}
}
/// Request parameters for the [`query_transfer_status`] operation.
///
/// This struct holds all of the inputs you can pass when calling
/// [`query_transfer_status`](#method.query_transfer_status).
#[derive(Clone, Debug, Builder)]
#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
pub struct QueryTransferStatusParams {
/// Transfer ID returned from outbound/inbound transfer
///
/// This field is **required.
#[builder(setter(into))]
pub transfer_id: String,
/// Request validity window in milliseconds
///
/// This field is **optional.
#[builder(setter(into), default)]
pub recv_window: Option<i64>,
}
impl QueryTransferStatusParams {
/// Create a builder for [`query_transfer_status`].
///
/// Required parameters:
///
/// * `transfer_id` — Transfer ID returned from outbound/inbound transfer
///
#[must_use]
pub fn builder(transfer_id: String) -> QueryTransferStatusParamsBuilder {
QueryTransferStatusParamsBuilder::default().transfer_id(transfer_id)
}
}
#[async_trait]
impl TransferApi for TransferApiClient {
async fn create_inbound_transfer(
&self,
params: CreateInboundTransferParams,
) -> anyhow::Result<RestApiResponse<models::CreateInboundTransferResponse>> {
let CreateInboundTransferParams {
wallet_id,
wallet_address,
from_token_amount,
account_type,
from_token,
to_token,
chain_id,
} = params;
let mut query_params = BTreeMap::new();
let body_params = BTreeMap::new();
query_params.insert("walletId".to_string(), json!(wallet_id));
query_params.insert("walletAddress".to_string(), json!(wallet_address));
query_params.insert("fromTokenAmount".to_string(), json!(from_token_amount));
query_params.insert("accountType".to_string(), json!(account_type));
if let Some(rw) = from_token {
query_params.insert("fromToken".to_string(), json!(rw));
}
if let Some(rw) = to_token {
query_params.insert("toToken".to_string(), json!(rw));
}
if let Some(rw) = chain_id {
query_params.insert("chainId".to_string(), json!(rw));
}
send_request::<models::CreateInboundTransferResponse>(
&self.configuration,
"/sapi/v1/w3w/wallet/prediction/transfer/inbound",
reqwest::Method::POST,
query_params,
body_params,
if HAS_TIME_UNIT {
self.configuration.time_unit
} else {
None
},
true,
)
.await
}
async fn create_outbound_transfer(
&self,
params: CreateOutboundTransferParams,
) -> anyhow::Result<RestApiResponse<models::CreateOutboundTransferResponse>> {
let CreateOutboundTransferParams {
wallet_id,
wallet_address,
from_token_amount,
account_type,
source_biz,
from_token,
to_token,
chain_id,
} = params;
let mut query_params = BTreeMap::new();
let body_params = BTreeMap::new();
query_params.insert("walletId".to_string(), json!(wallet_id));
query_params.insert("walletAddress".to_string(), json!(wallet_address));
query_params.insert("fromTokenAmount".to_string(), json!(from_token_amount));
query_params.insert("accountType".to_string(), json!(account_type));
query_params.insert("sourceBiz".to_string(), json!(source_biz));
if let Some(rw) = from_token {
query_params.insert("fromToken".to_string(), json!(rw));
}
if let Some(rw) = to_token {
query_params.insert("toToken".to_string(), json!(rw));
}
if let Some(rw) = chain_id {
query_params.insert("chainId".to_string(), json!(rw));
}
send_request::<models::CreateOutboundTransferResponse>(
&self.configuration,
"/sapi/v1/w3w/wallet/prediction/transfer/outbound",
reqwest::Method::POST,
query_params,
body_params,
if HAS_TIME_UNIT {
self.configuration.time_unit
} else {
None
},
true,
)
.await
}
async fn query_transfer_list(
&self,
params: QueryTransferListParams,
) -> anyhow::Result<RestApiResponse<models::QueryTransferListResponse>> {
let QueryTransferListParams {
wallet_address,
start_date,
end_date,
token_symbol,
direction,
offset,
limit,
recv_window,
} = params;
let mut query_params = BTreeMap::new();
let body_params = BTreeMap::new();
query_params.insert("walletAddress".to_string(), json!(wallet_address));
query_params.insert("startDate".to_string(), json!(start_date));
query_params.insert("endDate".to_string(), json!(end_date));
if let Some(rw) = token_symbol {
query_params.insert("tokenSymbol".to_string(), json!(rw));
}
if let Some(rw) = direction {
query_params.insert("direction".to_string(), json!(rw));
}
if let Some(rw) = offset {
query_params.insert("offset".to_string(), json!(rw));
}
if let Some(rw) = limit {
query_params.insert("limit".to_string(), json!(rw));
}
if let Some(rw) = recv_window {
query_params.insert("recvWindow".to_string(), json!(rw));
}
send_request::<models::QueryTransferListResponse>(
&self.configuration,
"/sapi/v1/w3w/wallet/prediction/transfer/list",
reqwest::Method::GET,
query_params,
body_params,
if HAS_TIME_UNIT {
self.configuration.time_unit
} else {
None
},
true,
)
.await
}
async fn query_transfer_status(
&self,
params: QueryTransferStatusParams,
) -> anyhow::Result<RestApiResponse<models::QueryTransferStatusResponse>> {
let QueryTransferStatusParams {
transfer_id,
recv_window,
} = params;
let mut query_params = BTreeMap::new();
let body_params = BTreeMap::new();
query_params.insert("transferId".to_string(), json!(transfer_id));
if let Some(rw) = recv_window {
query_params.insert("recvWindow".to_string(), json!(rw));
}
send_request::<models::QueryTransferStatusResponse>(
&self.configuration,
"/sapi/v1/w3w/wallet/prediction/transfer/status",
reqwest::Method::GET,
query_params,
body_params,
if HAS_TIME_UNIT {
self.configuration.time_unit
} else {
None
},
true,
)
.await
}
}
#[cfg(all(test, feature = "w3w_prediction"))]
mod tests {
use super::*;
use crate::TOKIO_SHARED_RT;
use crate::{errors::ConnectorError, models::DataFuture, models::RestApiRateLimit};
use async_trait::async_trait;
use std::collections::HashMap;
struct DummyRestApiResponse<T> {
inner: Box<dyn FnOnce() -> DataFuture<Result<T, ConnectorError>> + Send + Sync>,
status: u16,
headers: HashMap<String, String>,
rate_limits: Option<Vec<RestApiRateLimit>>,
}
impl<T> From<DummyRestApiResponse<T>> for RestApiResponse<T> {
fn from(dummy: DummyRestApiResponse<T>) -> Self {
Self {
data_fn: dummy.inner,
status: dummy.status,
headers: dummy.headers,
rate_limits: dummy.rate_limits,
}
}
}
struct MockTransferApiClient {
force_error: bool,
}
#[async_trait]
impl TransferApi for MockTransferApiClient {
async fn create_inbound_transfer(
&self,
_params: CreateInboundTransferParams,
) -> anyhow::Result<RestApiResponse<models::CreateInboundTransferResponse>> {
if self.force_error {
return Err(ConnectorError::ConnectorClientError {
msg: "ResponseError".to_string(),
code: None,
}
.into());
}
let resp_json: Value = serde_json::from_str(
r#"{"transferId":"tf_20260525_in_001","status":"PROCESSING"}"#,
)
.unwrap_or_else(|_| serde_json::json!({}));
let dummy_response: models::CreateInboundTransferResponse =
serde_json::from_value(resp_json.clone())
.expect("should parse into models::CreateInboundTransferResponse");
let dummy = DummyRestApiResponse {
inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
status: 200,
headers: HashMap::new(),
rate_limits: None,
};
Ok(dummy.into())
}
async fn create_outbound_transfer(
&self,
_params: CreateOutboundTransferParams,
) -> anyhow::Result<RestApiResponse<models::CreateOutboundTransferResponse>> {
if self.force_error {
return Err(ConnectorError::ConnectorClientError {
msg: "ResponseError".to_string(),
code: None,
}
.into());
}
let resp_json: Value = serde_json::from_str(
r#"{"transferId":"tf_20260525_out_001","status":"PROCESSING"}"#,
)
.unwrap_or_else(|_| serde_json::json!({}));
let dummy_response: models::CreateOutboundTransferResponse =
serde_json::from_value(resp_json.clone())
.expect("should parse into models::CreateOutboundTransferResponse");
let dummy = DummyRestApiResponse {
inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
status: 200,
headers: HashMap::new(),
rate_limits: None,
};
Ok(dummy.into())
}
async fn query_transfer_list(
&self,
_params: QueryTransferListParams,
) -> anyhow::Result<RestApiResponse<models::QueryTransferListResponse>> {
if self.force_error {
return Err(ConnectorError::ConnectorClientError {
msg: "ResponseError".to_string(),
code: None,
}
.into());
}
let resp_json: Value = serde_json::from_str(r#"{"transfers":[{"transferId":"tf_20260525_out_001","direction":"OUTBOUND","status":"SUCCESS","walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","fromToken":"USDT","fromTokenAmount":"100.00","toToken":"USDT","toTokenAmount":"100.00","errorCode":"errorCode","errorMessage":"errorMessage","createTime":"2026-05-25T04:00:00.000+00:00","updateTime":"2026-05-25T04:00:05.000+00:00","completeAt":"2026-05-25T04:00:05.000+00:00"}]}"#).unwrap_or_else(|_| serde_json::json!({}));
let dummy_response: models::QueryTransferListResponse =
serde_json::from_value(resp_json.clone())
.expect("should parse into models::QueryTransferListResponse");
let dummy = DummyRestApiResponse {
inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
status: 200,
headers: HashMap::new(),
rate_limits: None,
};
Ok(dummy.into())
}
async fn query_transfer_status(
&self,
_params: QueryTransferStatusParams,
) -> anyhow::Result<RestApiResponse<models::QueryTransferStatusResponse>> {
if self.force_error {
return Err(ConnectorError::ConnectorClientError {
msg: "ResponseError".to_string(),
code: None,
}
.into());
}
let resp_json: Value = serde_json::from_str(r#"{"transferId":"tf_20260525_out_001","direction":"OUTBOUND","status":"COMPLETED","fromToken":"USDT","fromTokenAmount":"100.00","toToken":"USDT","toTokenAmount":"100.00","errorCode":"errorCode","errorMessage":"errorMessage","createTime":"2026-05-25T04:00:00.000+00:00","updateTime":"2026-05-25T04:00:05.000+00:00"}"#).unwrap_or_else(|_| serde_json::json!({}));
let dummy_response: models::QueryTransferStatusResponse =
serde_json::from_value(resp_json.clone())
.expect("should parse into models::QueryTransferStatusResponse");
let dummy = DummyRestApiResponse {
inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
status: 200,
headers: HashMap::new(),
rate_limits: None,
};
Ok(dummy.into())
}
}
#[test]
fn create_inbound_transfer_required_params_success() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: false };
let params = CreateInboundTransferParams::builder(
"5b5c1ec3be4e4416a5872b21c1ca5d20".to_string(),
"0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),
"1000000000000000000".to_string(),
CreateInboundTransferAccountTypeEnum::Spot,
)
.build()
.unwrap();
let resp_json: Value = serde_json::from_str(
r#"{"transferId":"tf_20260525_in_001","status":"PROCESSING"}"#,
)
.unwrap_or_else(|_| serde_json::json!({}));
let expected_response: models::CreateInboundTransferResponse =
serde_json::from_value(resp_json.clone())
.expect("should parse into models::CreateInboundTransferResponse");
let resp = client
.create_inbound_transfer(params)
.await
.expect("Expected a response");
let data_future = resp.data();
let actual_response = data_future.await.unwrap();
assert_eq!(actual_response, expected_response);
});
}
#[test]
fn create_inbound_transfer_optional_params_success() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: false };
let params = CreateInboundTransferParams::builder(
"5b5c1ec3be4e4416a5872b21c1ca5d20".to_string(),
"0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),
"1000000000000000000".to_string(),
CreateInboundTransferAccountTypeEnum::Spot,
)
.from_token("USDT".to_string())
.to_token("USDT".to_string())
.chain_id("56".to_string())
.build()
.unwrap();
let resp_json: Value = serde_json::from_str(
r#"{"transferId":"tf_20260525_in_001","status":"PROCESSING"}"#,
)
.unwrap_or_else(|_| serde_json::json!({}));
let expected_response: models::CreateInboundTransferResponse =
serde_json::from_value(resp_json.clone())
.expect("should parse into models::CreateInboundTransferResponse");
let resp = client
.create_inbound_transfer(params)
.await
.expect("Expected a response");
let data_future = resp.data();
let actual_response = data_future.await.unwrap();
assert_eq!(actual_response, expected_response);
});
}
#[test]
fn create_inbound_transfer_response_error() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: true };
let params = CreateInboundTransferParams::builder(
"5b5c1ec3be4e4416a5872b21c1ca5d20".to_string(),
"0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),
"1000000000000000000".to_string(),
CreateInboundTransferAccountTypeEnum::Spot,
)
.build()
.unwrap();
match client.create_inbound_transfer(params).await {
Ok(_) => panic!("Expected an error"),
Err(err) => {
assert_eq!(err.to_string(), "Connector client error: ResponseError");
}
}
});
}
#[test]
fn create_outbound_transfer_required_params_success() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: false };
let params = CreateOutboundTransferParams::builder(
"5b5c1ec3be4e4416a5872b21c1ca5d20".to_string(),
"0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),
"1000000000000000000".to_string(),
CreateOutboundTransferAccountTypeEnum::Spot,
CreateOutboundTransferSourceBizEnum::UserTransfer,
)
.build()
.unwrap();
let resp_json: Value = serde_json::from_str(
r#"{"transferId":"tf_20260525_out_001","status":"PROCESSING"}"#,
)
.unwrap_or_else(|_| serde_json::json!({}));
let expected_response: models::CreateOutboundTransferResponse =
serde_json::from_value(resp_json.clone())
.expect("should parse into models::CreateOutboundTransferResponse");
let resp = client
.create_outbound_transfer(params)
.await
.expect("Expected a response");
let data_future = resp.data();
let actual_response = data_future.await.unwrap();
assert_eq!(actual_response, expected_response);
});
}
#[test]
fn create_outbound_transfer_optional_params_success() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: false };
let params = CreateOutboundTransferParams::builder(
"5b5c1ec3be4e4416a5872b21c1ca5d20".to_string(),
"0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),
"1000000000000000000".to_string(),
CreateOutboundTransferAccountTypeEnum::Spot,
CreateOutboundTransferSourceBizEnum::UserTransfer,
)
.from_token("USDT".to_string())
.to_token("USDT".to_string())
.chain_id("56".to_string())
.build()
.unwrap();
let resp_json: Value = serde_json::from_str(
r#"{"transferId":"tf_20260525_out_001","status":"PROCESSING"}"#,
)
.unwrap_or_else(|_| serde_json::json!({}));
let expected_response: models::CreateOutboundTransferResponse =
serde_json::from_value(resp_json.clone())
.expect("should parse into models::CreateOutboundTransferResponse");
let resp = client
.create_outbound_transfer(params)
.await
.expect("Expected a response");
let data_future = resp.data();
let actual_response = data_future.await.unwrap();
assert_eq!(actual_response, expected_response);
});
}
#[test]
fn create_outbound_transfer_response_error() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: true };
let params = CreateOutboundTransferParams::builder(
"5b5c1ec3be4e4416a5872b21c1ca5d20".to_string(),
"0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),
"1000000000000000000".to_string(),
CreateOutboundTransferAccountTypeEnum::Spot,
CreateOutboundTransferSourceBizEnum::UserTransfer,
)
.build()
.unwrap();
match client.create_outbound_transfer(params).await {
Ok(_) => panic!("Expected an error"),
Err(err) => {
assert_eq!(err.to_string(), "Connector client error: ResponseError");
}
}
});
}
#[test]
fn query_transfer_list_required_params_success() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: false };
let params = QueryTransferListParams::builder("0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),"2026-05-01".to_string(),"2026-05-25".to_string(),).build().unwrap();
let resp_json: Value = serde_json::from_str(r#"{"transfers":[{"transferId":"tf_20260525_out_001","direction":"OUTBOUND","status":"SUCCESS","walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","fromToken":"USDT","fromTokenAmount":"100.00","toToken":"USDT","toTokenAmount":"100.00","errorCode":"errorCode","errorMessage":"errorMessage","createTime":"2026-05-25T04:00:00.000+00:00","updateTime":"2026-05-25T04:00:05.000+00:00","completeAt":"2026-05-25T04:00:05.000+00:00"}]}"#).unwrap_or_else(|_| serde_json::json!({}));
let expected_response : models::QueryTransferListResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryTransferListResponse");
let resp = client.query_transfer_list(params).await.expect("Expected a response");
let data_future = resp.data();
let actual_response = data_future.await.unwrap();
assert_eq!(actual_response, expected_response);
});
}
#[test]
fn query_transfer_list_optional_params_success() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: false };
let params = QueryTransferListParams::builder("0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),"2026-05-01".to_string(),"2026-05-25".to_string(),).token_symbol("USDT".to_string()).direction(QueryTransferListDirectionEnum::Inbound).offset(0).limit(20).recv_window(5000).build().unwrap();
let resp_json: Value = serde_json::from_str(r#"{"transfers":[{"transferId":"tf_20260525_out_001","direction":"OUTBOUND","status":"SUCCESS","walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","fromToken":"USDT","fromTokenAmount":"100.00","toToken":"USDT","toTokenAmount":"100.00","errorCode":"errorCode","errorMessage":"errorMessage","createTime":"2026-05-25T04:00:00.000+00:00","updateTime":"2026-05-25T04:00:05.000+00:00","completeAt":"2026-05-25T04:00:05.000+00:00"}]}"#).unwrap_or_else(|_| serde_json::json!({}));
let expected_response : models::QueryTransferListResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryTransferListResponse");
let resp = client.query_transfer_list(params).await.expect("Expected a response");
let data_future = resp.data();
let actual_response = data_future.await.unwrap();
assert_eq!(actual_response, expected_response);
});
}
#[test]
fn query_transfer_list_response_error() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: true };
let params = QueryTransferListParams::builder(
"0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),
"2026-05-01".to_string(),
"2026-05-25".to_string(),
)
.build()
.unwrap();
match client.query_transfer_list(params).await {
Ok(_) => panic!("Expected an error"),
Err(err) => {
assert_eq!(err.to_string(), "Connector client error: ResponseError");
}
}
});
}
#[test]
fn query_transfer_status_required_params_success() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: false };
let params = QueryTransferStatusParams::builder("tf_20260525_out_001".to_string(),).build().unwrap();
let resp_json: Value = serde_json::from_str(r#"{"transferId":"tf_20260525_out_001","direction":"OUTBOUND","status":"COMPLETED","fromToken":"USDT","fromTokenAmount":"100.00","toToken":"USDT","toTokenAmount":"100.00","errorCode":"errorCode","errorMessage":"errorMessage","createTime":"2026-05-25T04:00:00.000+00:00","updateTime":"2026-05-25T04:00:05.000+00:00"}"#).unwrap_or_else(|_| serde_json::json!({}));
let expected_response : models::QueryTransferStatusResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryTransferStatusResponse");
let resp = client.query_transfer_status(params).await.expect("Expected a response");
let data_future = resp.data();
let actual_response = data_future.await.unwrap();
assert_eq!(actual_response, expected_response);
});
}
#[test]
fn query_transfer_status_optional_params_success() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: false };
let params = QueryTransferStatusParams::builder("tf_20260525_out_001".to_string(),).recv_window(5000).build().unwrap();
let resp_json: Value = serde_json::from_str(r#"{"transferId":"tf_20260525_out_001","direction":"OUTBOUND","status":"COMPLETED","fromToken":"USDT","fromTokenAmount":"100.00","toToken":"USDT","toTokenAmount":"100.00","errorCode":"errorCode","errorMessage":"errorMessage","createTime":"2026-05-25T04:00:00.000+00:00","updateTime":"2026-05-25T04:00:05.000+00:00"}"#).unwrap_or_else(|_| serde_json::json!({}));
let expected_response : models::QueryTransferStatusResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryTransferStatusResponse");
let resp = client.query_transfer_status(params).await.expect("Expected a response");
let data_future = resp.data();
let actual_response = data_future.await.unwrap();
assert_eq!(actual_response, expected_response);
});
}
#[test]
fn query_transfer_status_response_error() {
TOKIO_SHARED_RT.block_on(async {
let client = MockTransferApiClient { force_error: true };
let params = QueryTransferStatusParams::builder("tf_20260525_out_001".to_string())
.build()
.unwrap();
match client.query_transfer_status(params).await {
Ok(_) => panic!("Expected an error"),
Err(err) => {
assert_eq!(err.to_string(), "Connector client error: ResponseError");
}
}
});
}
}