@@ -4,14 +4,17 @@ use sp_std::prelude::*;
4
4
#[ cfg( test) ]
5
5
use crate :: {
6
6
CommitmentInfo , CommitmentOf , Config , Data , Error , Event , MaxSpace , Pallet , RateLimit ,
7
- RevealedCommitments , TimelockedIndex ,
7
+ Registration , RevealedCommitments , TimelockedIndex ,
8
8
mock:: {
9
- DRAND_QUICKNET_SIG_HEX , RuntimeEvent , RuntimeOrigin , Test , insert_drand_pulse,
9
+ Balances , DRAND_QUICKNET_SIG_HEX , RuntimeEvent , RuntimeOrigin , Test , insert_drand_pulse,
10
10
new_test_ext, produce_ciphertext,
11
11
} ,
12
12
} ;
13
13
use frame_support:: pallet_prelude:: Hooks ;
14
- use frame_support:: { BoundedVec , assert_noop, assert_ok, traits:: Get } ;
14
+ use frame_support:: {
15
+ BoundedVec , assert_noop, assert_ok,
16
+ traits:: { Currency , Get , ReservableCurrency } ,
17
+ } ;
15
18
use frame_system:: Pallet as System ;
16
19
17
20
#[ allow( clippy:: indexing_slicing) ]
@@ -1220,3 +1223,42 @@ fn on_initialize_reveals_matured_timelocks() {
1220
1223
}
1221
1224
} ) ;
1222
1225
}
1226
+
1227
+ #[ test]
1228
+ fn set_commitment_unreserve_leftover_fails ( ) {
1229
+ new_test_ext ( ) . execute_with ( || {
1230
+ use frame_system:: RawOrigin ;
1231
+
1232
+ let netuid = 999 ;
1233
+ let who = 99 ;
1234
+
1235
+ Balances :: make_free_balance_be ( & who, 10_000 ) ;
1236
+
1237
+ let fake_deposit = 100 ;
1238
+ let dummy_info = CommitmentInfo {
1239
+ fields : BoundedVec :: try_from ( vec ! [ ] ) . expect ( "empty fields is fine" ) ,
1240
+ } ;
1241
+ let registration = Registration {
1242
+ deposit : fake_deposit,
1243
+ info : dummy_info,
1244
+ block : 0u64 . into ( ) ,
1245
+ } ;
1246
+
1247
+ CommitmentOf :: < Test > :: insert ( netuid, who, registration) ;
1248
+
1249
+ assert_ok ! ( Balances :: reserve( & who, fake_deposit) ) ;
1250
+ assert_eq ! ( Balances :: reserved_balance( who) , 100 ) ;
1251
+
1252
+ Balances :: unreserve ( & who, 10_000 ) ;
1253
+ assert_eq ! ( Balances :: reserved_balance( who) , 0 ) ;
1254
+
1255
+ let commit_small = Box :: new ( CommitmentInfo {
1256
+ fields : BoundedVec :: try_from ( vec ! [ ] ) . expect ( "no fields is fine" ) ,
1257
+ } ) ;
1258
+
1259
+ assert_noop ! (
1260
+ Pallet :: <Test >:: set_commitment( RawOrigin :: Signed ( who) . into( ) , netuid, commit_small) ,
1261
+ Error :: <Test >:: UnexpectedUnreserveLeftover
1262
+ ) ;
1263
+ } ) ;
1264
+ }
0 commit comments