@@ -486,17 +486,21 @@ pub fn launch_cns(
486
486
mod tests {
487
487
use chia:: {
488
488
clvm_utils:: CurriedProgram ,
489
- protocol:: SpendBundle ,
490
- puzzles:: { cat:: GenesisByCoinIdTailArgs , singleton:: SINGLETON_LAUNCHER_PUZZLE_HASH } ,
489
+ protocol:: { Bytes , SpendBundle } ,
490
+ puzzles:: {
491
+ cat:: GenesisByCoinIdTailArgs ,
492
+ singleton:: { SingletonSolution , SINGLETON_LAUNCHER_PUZZLE_HASH } ,
493
+ } ,
491
494
} ;
492
495
use chia_wallet_sdk:: {
493
- test_secret_keys, Nft , NftMint , Simulator , SpendWithConditions , TESTNET11_CONSTANTS ,
496
+ test_secret_keys, Nft , NftMint , Simulator , SingletonLayer , SpendWithConditions ,
497
+ TESTNET11_CONSTANTS ,
494
498
} ;
495
499
use hex_literal:: hex;
496
500
497
501
use crate :: {
498
502
AddCatInfo , CatNftMetadata , CatalogPrecommitValue , CnsPrecommitValue , CnsRegisterAction ,
499
- PrecommitCoin , SlotNeigborsInfo , SpendContextExt , ANY_METADATA_UPDATER_HASH ,
503
+ PrecommitCoin , Reserve , SlotNeigborsInfo , SpendContextExt , ANY_METADATA_UPDATER_HASH ,
500
504
SLOT32_MAX_VALUE , SLOT32_MIN_VALUE ,
501
505
} ;
502
506
@@ -1080,4 +1084,72 @@ mod tests {
1080
1084
1081
1085
Ok ( ( ) )
1082
1086
}
1087
+
1088
+ #[ test]
1089
+ fn test_xch_reserve ( ) -> anyhow:: Result < ( ) > {
1090
+ let ctx = & mut SpendContext :: new ( ) ;
1091
+ let mut sim = Simulator :: new ( ) ;
1092
+
1093
+ // we are creating 101 mojos
1094
+ // one will go into the controller singleton
1095
+ // 100 will go into the reserve, which will then be spent
1096
+ // the same 100 mojos will be reserved as fee - tx only goes through if all spends are successful
1097
+ let ( sk, pk, p2_puzzle_hash, coin) = sim. new_p2 ( 101 ) ?;
1098
+ let p2 = StandardLayer :: new ( pk) ;
1099
+
1100
+ let launcher = Launcher :: new ( coin. coin_id ( ) , 1 ) ;
1101
+ let ( create_launcher, controller_coin) = launcher. clone ( ) . spend ( ctx, p2_puzzle_hash, ( ) ) ?;
1102
+ let launcher_id = controller_coin. parent_coin_info ;
1103
+
1104
+ let reserve = Reserve :: new ( coin. coin_id ( ) , 100 , launcher_id, ( ) ) ;
1105
+ p2. spend (
1106
+ ctx,
1107
+ coin,
1108
+ create_launcher
1109
+ . create_coin ( reserve. coin . puzzle_hash , 100 , vec ! [ ] )
1110
+ . reserve_fee ( 100 ) ,
1111
+ ) ?;
1112
+
1113
+ let reserve_ph = reserve. coin . puzzle_hash ;
1114
+ reserve. spend ( ctx, p2_puzzle_hash) ?;
1115
+
1116
+ let controller_output_conds = Conditions :: new ( )
1117
+ . create_coin ( p2_puzzle_hash, 1 , vec ! [ ] )
1118
+ . send_message (
1119
+ 19 ,
1120
+ Bytes :: default ( ) ,
1121
+ vec ! [ ctx. alloc( & reserve_ph) ?, ctx. alloc( & 100 ) ?] ,
1122
+ ) ;
1123
+ let controller_delegated_puzzle =
1124
+ clvm_quote ! ( controller_output_conds) . to_clvm ( & mut ctx. allocator ) ?;
1125
+
1126
+ let controller: SingletonLayer < StandardLayer > = SingletonLayer :: new ( launcher_id, p2) ;
1127
+ let controller_puzzle = controller. construct_puzzle ( ctx) ?;
1128
+ let controller_solution = controller. construct_solution (
1129
+ ctx,
1130
+ SingletonSolution {
1131
+ lineage_proof : Proof :: Eve ( EveProof {
1132
+ parent_parent_coin_info : launcher. coin ( ) . parent_coin_info ,
1133
+ parent_amount : 1 ,
1134
+ } ) ,
1135
+ amount : 1 ,
1136
+ inner_solution : StandardSolution {
1137
+ original_public_key : None ,
1138
+ delegated_puzzle : controller_delegated_puzzle,
1139
+ solution : ctx. allocator . nil ( ) ,
1140
+ } ,
1141
+ } ,
1142
+ ) ?;
1143
+
1144
+ let controller_puzzle = ctx. serialize ( & controller_puzzle) ?;
1145
+ let controller_solution = ctx. serialize ( & controller_solution) ?;
1146
+ ctx. insert ( CoinSpend :: new (
1147
+ controller_coin,
1148
+ controller_puzzle,
1149
+ controller_solution,
1150
+ ) ) ;
1151
+
1152
+ sim. spend_coins ( ctx. take ( ) , & [ sk] ) ?;
1153
+ Ok ( ( ) )
1154
+ }
1083
1155
}
0 commit comments