mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 20:51:05 +00:00
add some basic tests for swap tokens (#1164)
This commit is contained in:
committed by
Bastian Köcher
parent
f2092515a0
commit
84258f5d8c
@@ -41,7 +41,7 @@ use crate::cli::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Swap tokens.
|
/// Swap tokens.
|
||||||
#[derive(StructOpt)]
|
#[derive(StructOpt, Debug, PartialEq)]
|
||||||
pub struct SwapTokens {
|
pub struct SwapTokens {
|
||||||
/// A bridge instance to use in token swap.
|
/// A bridge instance to use in token swap.
|
||||||
#[structopt(possible_values = SwapTokensBridge::VARIANTS, case_insensitive = true)]
|
#[structopt(possible_values = SwapTokensBridge::VARIANTS, case_insensitive = true)]
|
||||||
@@ -85,7 +85,7 @@ pub enum TokenSwapType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Swap tokens bridge.
|
/// Swap tokens bridge.
|
||||||
#[derive(Debug, EnumString, EnumVariantNames)]
|
#[derive(Debug, EnumString, EnumVariantNames, PartialEq)]
|
||||||
#[strum(serialize_all = "kebab_case")]
|
#[strum(serialize_all = "kebab_case")]
|
||||||
pub enum SwapTokensBridge {
|
pub enum SwapTokensBridge {
|
||||||
/// Use token-swap pallet deployed at Millau to swap tokens with Rialto.
|
/// Use token-swap pallet deployed at Millau to swap tokens with Rialto.
|
||||||
@@ -665,3 +665,131 @@ async fn read_token_swap_state<C: Chain>(
|
|||||||
) -> anyhow::Result<Option<bp_token_swap::TokenSwapState>> {
|
) -> anyhow::Result<Option<bp_token_swap::TokenSwapState>> {
|
||||||
Ok(client.storage_value(swap_state_storage_key.clone(), Some(at_block)).await?)
|
Ok(client.storage_value(swap_state_storage_key.clone(), Some(at_block)).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn swap_tokens_millau_to_rialto_no_lock() {
|
||||||
|
let swap_tokens = SwapTokens::from_iter(vec![
|
||||||
|
"swap-tokens",
|
||||||
|
"millau-to-rialto",
|
||||||
|
"--source-host",
|
||||||
|
"127.0.0.1",
|
||||||
|
"--source-port",
|
||||||
|
"9000",
|
||||||
|
"--source-signer",
|
||||||
|
"//Alice",
|
||||||
|
"--source-balance",
|
||||||
|
"8000000000",
|
||||||
|
"--target-host",
|
||||||
|
"127.0.0.1",
|
||||||
|
"--target-port",
|
||||||
|
"9001",
|
||||||
|
"--target-signer",
|
||||||
|
"//Bob",
|
||||||
|
"--target-balance",
|
||||||
|
"9000000000",
|
||||||
|
"no-lock",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
swap_tokens,
|
||||||
|
SwapTokens {
|
||||||
|
bridge: SwapTokensBridge::MillauToRialto,
|
||||||
|
source: SourceConnectionParams {
|
||||||
|
source_host: "127.0.0.1".into(),
|
||||||
|
source_port: 9000,
|
||||||
|
source_secure: false,
|
||||||
|
},
|
||||||
|
source_sign: SourceSigningParams {
|
||||||
|
source_signer: Some("//Alice".into()),
|
||||||
|
source_signer_password: None,
|
||||||
|
source_signer_file: None,
|
||||||
|
source_signer_password_file: None,
|
||||||
|
source_transactions_mortality: None,
|
||||||
|
},
|
||||||
|
target: TargetConnectionParams {
|
||||||
|
target_host: "127.0.0.1".into(),
|
||||||
|
target_port: 9001,
|
||||||
|
target_secure: false,
|
||||||
|
},
|
||||||
|
target_sign: TargetSigningParams {
|
||||||
|
target_signer: Some("//Bob".into()),
|
||||||
|
target_signer_password: None,
|
||||||
|
target_signer_file: None,
|
||||||
|
target_signer_password_file: None,
|
||||||
|
target_transactions_mortality: None,
|
||||||
|
},
|
||||||
|
swap_type: TokenSwapType::NoLock,
|
||||||
|
source_balance: Balance(8000000000),
|
||||||
|
target_balance: Balance(9000000000),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn swap_tokens_millau_to_rialto_lock_until() {
|
||||||
|
let swap_tokens = SwapTokens::from_iter(vec![
|
||||||
|
"swap-tokens",
|
||||||
|
"millau-to-rialto",
|
||||||
|
"--source-host",
|
||||||
|
"127.0.0.1",
|
||||||
|
"--source-port",
|
||||||
|
"9000",
|
||||||
|
"--source-signer",
|
||||||
|
"//Alice",
|
||||||
|
"--source-balance",
|
||||||
|
"8000000000",
|
||||||
|
"--target-host",
|
||||||
|
"127.0.0.1",
|
||||||
|
"--target-port",
|
||||||
|
"9001",
|
||||||
|
"--target-signer",
|
||||||
|
"//Bob",
|
||||||
|
"--target-balance",
|
||||||
|
"9000000000",
|
||||||
|
"lock-until-block",
|
||||||
|
"--blocks-before-expire",
|
||||||
|
"1",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
swap_tokens,
|
||||||
|
SwapTokens {
|
||||||
|
bridge: SwapTokensBridge::MillauToRialto,
|
||||||
|
source: SourceConnectionParams {
|
||||||
|
source_host: "127.0.0.1".into(),
|
||||||
|
source_port: 9000,
|
||||||
|
source_secure: false,
|
||||||
|
},
|
||||||
|
source_sign: SourceSigningParams {
|
||||||
|
source_signer: Some("//Alice".into()),
|
||||||
|
source_signer_password: None,
|
||||||
|
source_signer_file: None,
|
||||||
|
source_signer_password_file: None,
|
||||||
|
source_transactions_mortality: None,
|
||||||
|
},
|
||||||
|
target: TargetConnectionParams {
|
||||||
|
target_host: "127.0.0.1".into(),
|
||||||
|
target_port: 9001,
|
||||||
|
target_secure: false,
|
||||||
|
},
|
||||||
|
target_sign: TargetSigningParams {
|
||||||
|
target_signer: Some("//Bob".into()),
|
||||||
|
target_signer_password: None,
|
||||||
|
target_signer_file: None,
|
||||||
|
target_signer_password_file: None,
|
||||||
|
target_transactions_mortality: None,
|
||||||
|
},
|
||||||
|
swap_type: TokenSwapType::LockUntilBlock {
|
||||||
|
blocks_before_expire: 1,
|
||||||
|
swap_nonce: None,
|
||||||
|
},
|
||||||
|
source_balance: Balance(8000000000),
|
||||||
|
target_balance: Balance(9000000000),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user