@@ -2780,6 +2780,7 @@ async fn test_split_coin() -> Result<(), anyhow::Error> {
2780
2780
. await ;
2781
2781
let rgp = test_cluster. get_reference_gas_price ( ) . await ;
2782
2782
let address = test_cluster. get_address_0 ( ) ;
2783
+ let address_1 = test_cluster. get_address_1 ( ) ;
2783
2784
let context = & mut test_cluster. wallet ;
2784
2785
let client = context. get_client ( ) . await ?;
2785
2786
let object_refs = client
@@ -2976,6 +2977,61 @@ async fn test_split_coin() -> Result<(), anyhow::Error> {
2976
2977
assert_eq ! ( get_gas_value( & updated_coin) + 1000 + 10 , orig_value) ;
2977
2978
assert ! ( ( get_gas_value( & new_coins[ 0 ] ) == 1000 ) || ( get_gas_value( & new_coins[ 0 ] ) == 10 ) ) ;
2978
2979
assert ! ( ( get_gas_value( & new_coins[ 1 ] ) == 1000 ) || ( get_gas_value( & new_coins[ 1 ] ) == 10 ) ) ;
2980
+
2981
+ // Test with single gas coin
2982
+ context. config_mut ( ) . set_active_address ( Some ( address_1) ) ;
2983
+ let object_refs = client
2984
+ . coin_read_api ( )
2985
+ . get_coins ( address_1, None , None , None )
2986
+ . await ?;
2987
+ // First merge all coins so we only have a single one left
2988
+ let resp = IotaClientCommands :: PayAllIota {
2989
+ input_coins : object_refs. data . iter ( ) . map ( |o| o. coin_object_id ) . collect ( ) ,
2990
+ recipient : KeyIdentity :: Address ( address_1) ,
2991
+ opts : Opts :: for_testing ( rgp * TEST_ONLY_GAS_UNIT_FOR_TRANSFER ) ,
2992
+ }
2993
+ . execute ( context)
2994
+ . await ?;
2995
+ if let IotaClientCommandResult :: TransactionBlock ( r) = resp {
2996
+ assert ! ( r. status_ok( ) . unwrap( ) , "Command PayAllIota failed: {r:?}" ) ;
2997
+ } else {
2998
+ panic ! ( "Command PayAllIota failed" )
2999
+ } ;
3000
+
3001
+ let object_refs = client
3002
+ . coin_read_api ( )
3003
+ . get_coins ( address_1, None , None , None )
3004
+ . await ?;
3005
+ assert_eq ! ( object_refs. data. len( ) , 1 , "More than one coin" ) ;
3006
+
3007
+ let gas = object_refs. data . first ( ) . unwrap ( ) . coin_object_id ;
3008
+ let resp = IotaClientCommands :: SplitCoin {
3009
+ opts : OptsWithGas :: for_testing ( None , rgp * TEST_ONLY_GAS_UNIT_FOR_SPLIT_COIN ) ,
3010
+ coin_id : gas,
3011
+ amounts : Some ( vec ! [ 10 , 1000 ] ) ,
3012
+ count : None ,
3013
+ }
3014
+ . execute ( context)
3015
+ . await ?;
3016
+
3017
+ let new_coins = if let IotaClientCommandResult :: TransactionBlock ( r) = resp {
3018
+ assert ! ( r. status_ok( ) . unwrap( ) , "Command SplitCoin failed: {r:?}" ) ;
3019
+ let effects = r. effects . as_ref ( ) . unwrap ( ) ;
3020
+ assert_eq ! ( effects. gas_object( ) . object_id( ) , gas) ;
3021
+
3022
+ let new_object_refs = effects. created ( ) . to_vec ( ) ;
3023
+ let mut new_objects = Vec :: with_capacity ( new_object_refs. len ( ) ) ;
3024
+ for obj_ref in new_object_refs {
3025
+ new_objects. push (
3026
+ get_parsed_object_assert_existence ( obj_ref. reference . object_id , context) . await ,
3027
+ ) ;
3028
+ }
3029
+ new_objects
3030
+ } else {
3031
+ panic ! ( "Command SplitCoin failed" )
3032
+ } ;
3033
+ assert ! ( ( get_gas_value( & new_coins[ 0 ] ) == 10 ) || ( get_gas_value( & new_coins[ 0 ] ) == 1000 ) ) ;
3034
+ assert ! ( ( get_gas_value( & new_coins[ 1 ] ) == 1000 ) || ( get_gas_value( & new_coins[ 1 ] ) == 10 ) ) ;
2979
3035
Ok ( ( ) )
2980
3036
}
2981
3037
0 commit comments