@@ -41,7 +41,7 @@ use crate::cli::{
4141} ;
4242
4343/// Swap tokens.
44- #[ derive( StructOpt ) ]
44+ #[ derive( StructOpt , Debug , PartialEq ) ]
4545pub struct SwapTokens {
4646 /// A bridge instance to use in token swap.
4747 #[ structopt( possible_values = SwapTokensBridge :: VARIANTS , case_insensitive = true ) ]
@@ -85,7 +85,7 @@ pub enum TokenSwapType {
8585}
8686
8787/// Swap tokens bridge.
88- #[ derive( Debug , EnumString , EnumVariantNames ) ]
88+ #[ derive( Debug , EnumString , EnumVariantNames , PartialEq ) ]
8989#[ strum( serialize_all = "kebab_case" ) ]
9090pub enum SwapTokensBridge {
9191 /// Use token-swap pallet deployed at Millau to swap tokens with Rialto.
@@ -665,3 +665,131 @@ async fn read_token_swap_state<C: Chain>(
665665) -> anyhow:: Result < Option < bp_token_swap:: TokenSwapState > > {
666666 Ok ( client. storage_value ( swap_state_storage_key. clone ( ) , Some ( at_block) ) . await ?)
667667}
668+
669+ #[ cfg( test) ]
670+ mod tests {
671+ use super :: * ;
672+
673+ #[ test]
674+ fn swap_tokens_millau_to_rialto_no_lock ( ) {
675+ let swap_tokens = SwapTokens :: from_iter ( vec ! [
676+ "swap-tokens" ,
677+ "millau-to-rialto" ,
678+ "--source-host" ,
679+ "127.0.0.1" ,
680+ "--source-port" ,
681+ "9000" ,
682+ "--source-signer" ,
683+ "//Alice" ,
684+ "--source-balance" ,
685+ "8000000000" ,
686+ "--target-host" ,
687+ "127.0.0.1" ,
688+ "--target-port" ,
689+ "9001" ,
690+ "--target-signer" ,
691+ "//Bob" ,
692+ "--target-balance" ,
693+ "9000000000" ,
694+ "no-lock" ,
695+ ] ) ;
696+
697+ assert_eq ! (
698+ swap_tokens,
699+ SwapTokens {
700+ bridge: SwapTokensBridge :: MillauToRialto ,
701+ source: SourceConnectionParams {
702+ source_host: "127.0.0.1" . into( ) ,
703+ source_port: 9000 ,
704+ source_secure: false ,
705+ } ,
706+ source_sign: SourceSigningParams {
707+ source_signer: Some ( "//Alice" . into( ) ) ,
708+ source_signer_password: None ,
709+ source_signer_file: None ,
710+ source_signer_password_file: None ,
711+ source_transactions_mortality: None ,
712+ } ,
713+ target: TargetConnectionParams {
714+ target_host: "127.0.0.1" . into( ) ,
715+ target_port: 9001 ,
716+ target_secure: false ,
717+ } ,
718+ target_sign: TargetSigningParams {
719+ target_signer: Some ( "//Bob" . into( ) ) ,
720+ target_signer_password: None ,
721+ target_signer_file: None ,
722+ target_signer_password_file: None ,
723+ target_transactions_mortality: None ,
724+ } ,
725+ swap_type: TokenSwapType :: NoLock ,
726+ source_balance: Balance ( 8000000000 ) ,
727+ target_balance: Balance ( 9000000000 ) ,
728+ }
729+ ) ;
730+ }
731+
732+ #[ test]
733+ fn swap_tokens_millau_to_rialto_lock_until ( ) {
734+ let swap_tokens = SwapTokens :: from_iter ( vec ! [
735+ "swap-tokens" ,
736+ "millau-to-rialto" ,
737+ "--source-host" ,
738+ "127.0.0.1" ,
739+ "--source-port" ,
740+ "9000" ,
741+ "--source-signer" ,
742+ "//Alice" ,
743+ "--source-balance" ,
744+ "8000000000" ,
745+ "--target-host" ,
746+ "127.0.0.1" ,
747+ "--target-port" ,
748+ "9001" ,
749+ "--target-signer" ,
750+ "//Bob" ,
751+ "--target-balance" ,
752+ "9000000000" ,
753+ "lock-until-block" ,
754+ "--blocks-before-expire" ,
755+ "1" ,
756+ ] ) ;
757+
758+ assert_eq ! (
759+ swap_tokens,
760+ SwapTokens {
761+ bridge: SwapTokensBridge :: MillauToRialto ,
762+ source: SourceConnectionParams {
763+ source_host: "127.0.0.1" . into( ) ,
764+ source_port: 9000 ,
765+ source_secure: false ,
766+ } ,
767+ source_sign: SourceSigningParams {
768+ source_signer: Some ( "//Alice" . into( ) ) ,
769+ source_signer_password: None ,
770+ source_signer_file: None ,
771+ source_signer_password_file: None ,
772+ source_transactions_mortality: None ,
773+ } ,
774+ target: TargetConnectionParams {
775+ target_host: "127.0.0.1" . into( ) ,
776+ target_port: 9001 ,
777+ target_secure: false ,
778+ } ,
779+ target_sign: TargetSigningParams {
780+ target_signer: Some ( "//Bob" . into( ) ) ,
781+ target_signer_password: None ,
782+ target_signer_file: None ,
783+ target_signer_password_file: None ,
784+ target_transactions_mortality: None ,
785+ } ,
786+ swap_type: TokenSwapType :: LockUntilBlock {
787+ blocks_before_expire: 1 ,
788+ swap_nonce: None ,
789+ } ,
790+ source_balance: Balance ( 8000000000 ) ,
791+ target_balance: Balance ( 9000000000 ) ,
792+ }
793+ ) ;
794+ }
795+ }
0 commit comments