@@ -6,7 +6,7 @@ use hydradx_traits::OraclePeriod;
66use sp_runtime:: Permill ;
77
88#[ test]
9- fn update_asset_peg_source_should_work_when_preserve_price_is_true ( ) {
9+ fn update_asset_peg_source_should_work ( ) {
1010 let asset_a: AssetId = 1 ;
1111 let asset_b: AssetId = 2 ;
1212 let pool_id = 100 ;
@@ -41,14 +41,13 @@ fn update_asset_peg_source_should_work_when_preserve_price_is_true() {
4141 let initial_peg_info = PoolPegs :: < Test > :: get ( pool_id) . unwrap ( ) ;
4242 let initial_price = initial_peg_info. current [ 0 ] ;
4343
44- // Update peg source for asset_a with preserve_price=true
44+ // Update peg source for asset_a (price always preserved)
4545 let new_peg_source = PegSource :: Value ( ( 2 , 3 ) ) ;
4646 assert_ok ! ( Stableswap :: update_asset_peg_source(
4747 RuntimeOrigin :: root( ) ,
4848 pool_id,
4949 asset_a,
5050 new_peg_source. clone( ) ,
51- true , // preserve_price
5251 ) ) ;
5352
5453 // Check that peg source was updated
@@ -71,7 +70,7 @@ fn update_asset_peg_source_should_work_when_preserve_price_is_true() {
7170}
7271
7372#[ test]
74- fn update_asset_peg_source_should_work_when_preserve_price_is_false ( ) {
73+ fn update_asset_peg_source_should_preserve_price ( ) {
7574 let asset_a: AssetId = 1 ;
7675 let asset_b: AssetId = 2 ;
7776 let pool_id = 100 ;
@@ -102,22 +101,25 @@ fn update_asset_peg_source_should_work_when_preserve_price_is_false() {
102101 Permill :: from_percent( 10 ) ,
103102 ) ) ;
104103
105- // Update peg source for asset_a with preserve_price=false
104+ // Get initial price to verify it's preserved
105+ let initial_peg_info = PoolPegs :: < Test > :: get ( pool_id) . unwrap ( ) ;
106+ let initial_price = initial_peg_info. current [ 0 ] ;
107+
108+ // Update peg source for asset_a (price always preserved)
106109 let new_peg_source = PegSource :: Value ( ( 2 , 3 ) ) ;
107110 assert_ok ! ( Stableswap :: update_asset_peg_source(
108111 RuntimeOrigin :: root( ) ,
109112 pool_id,
110113 asset_a,
111114 new_peg_source. clone( ) ,
112- false , // don't preserve_price
113115 ) ) ;
114116
115117 // Check that peg source was updated
116118 let updated_peg_info = PoolPegs :: < Test > :: get ( pool_id) . unwrap ( ) ;
117119 assert_eq ! ( updated_peg_info. source[ 0 ] , new_peg_source) ;
118120
119- // Check that price was updated to new value
120- assert_eq ! ( updated_peg_info. current[ 0 ] , ( 2 , 3 ) ) ;
121+ // Check that price was preserved (not updated)
122+ assert_eq ! ( updated_peg_info. current[ 0 ] , initial_price ) ;
121123
122124 // Check event was emitted
123125 System :: assert_last_event (
@@ -149,7 +151,6 @@ fn update_asset_peg_source_should_fail_when_pool_not_found() {
149151 pool_id, // Pool doesn't exist
150152 asset_a,
151153 new_peg_source,
152- true ,
153154 ) ,
154155 Error :: <Test >:: PoolNotFound
155156 ) ;
@@ -186,7 +187,7 @@ fn update_asset_peg_source_should_fail_when_pool_has_no_pegs() {
186187 let new_peg_source = PegSource :: Value ( ( 2 , 3 ) ) ;
187188
188189 assert_noop ! (
189- Stableswap :: update_asset_peg_source( RuntimeOrigin :: root( ) , pool_id, asset_a, new_peg_source, true , ) ,
190+ Stableswap :: update_asset_peg_source( RuntimeOrigin :: root( ) , pool_id, asset_a, new_peg_source, ) ,
190191 Error :: <Test >:: NoPegSource
191192 ) ;
192193 } ) ;
@@ -235,7 +236,6 @@ fn update_asset_peg_source_should_fail_when_asset_not_in_pool() {
235236 pool_id,
236237 asset_c, // Not in pool
237238 new_peg_source,
238- true ,
239239 ) ,
240240 Error :: <Test >:: AssetNotInPool
241241 ) ;
@@ -279,14 +279,14 @@ fn update_asset_peg_source_should_fail_when_invalid_origin() {
279279
280280 // BOB doesn't have UpdateTradabilityOrigin permission
281281 assert_noop ! (
282- Stableswap :: update_asset_peg_source( RuntimeOrigin :: signed( BOB ) , pool_id, asset_a, new_peg_source, true , ) ,
282+ Stableswap :: update_asset_peg_source( RuntimeOrigin :: signed( BOB ) , pool_id, asset_a, new_peg_source, ) ,
283283 sp_runtime:: DispatchError :: BadOrigin
284284 ) ;
285285 } ) ;
286286}
287287
288288#[ test]
289- fn update_asset_peg_source_should_fail_when_oracle_entry_missing ( ) {
289+ fn update_asset_peg_source_should_work_with_oracle_source ( ) {
290290 let asset_a: AssetId = 1 ;
291291 let asset_b: AssetId = 2 ;
292292 let pool_id = 100 ;
@@ -317,19 +317,19 @@ fn update_asset_peg_source_should_fail_when_oracle_entry_missing() {
317317 Permill :: from_percent( 10 ) ,
318318 ) ) ;
319319
320- // Try to update with oracle source that doesn't exist
321- let invalid_oracle_source = PegSource :: Oracle ( ( * b"nonexist" , OraclePeriod :: LastBlock , asset_a) ) ;
320+ // Update with oracle source (should work since price is always preserved)
321+ let oracle_source = PegSource :: Oracle ( ( * b"nonexist" , OraclePeriod :: LastBlock , asset_a) ) ;
322322
323- assert_noop ! (
324- Stableswap :: update_asset_peg_source (
325- RuntimeOrigin :: root ( ) ,
326- pool_id ,
327- asset_a ,
328- invalid_oracle_source ,
329- false , // This will try to fetch from oracle
330- ) ,
331- Error :: <Test >:: MissingTargetPegOracle
332- ) ;
323+ assert_ok ! ( Stableswap :: update_asset_peg_source (
324+ RuntimeOrigin :: root ( ) ,
325+ pool_id ,
326+ asset_a ,
327+ oracle_source . clone ( ) ,
328+ ) ) ;
329+
330+ // Check that peg source was updated
331+ let updated_peg_info = PoolPegs :: < Test > :: get ( pool_id ) . unwrap ( ) ;
332+ assert_eq ! ( updated_peg_info . source [ 0 ] , oracle_source ) ;
333333 } ) ;
334334}
335335
@@ -370,24 +370,23 @@ fn update_asset_peg_source_should_update_second_asset_correctly() {
370370 let initial_price_a = initial_peg_info. current [ 0 ] ;
371371 let _initial_price_b = initial_peg_info. current [ 1 ] ;
372372
373- // Update peg source for asset_b (index 1) with preserve_price=false
373+ // Update peg source for asset_b (index 1) - price will be preserved
374374 let new_peg_source = PegSource :: Value ( ( 3 , 4 ) ) ;
375375 assert_ok ! ( Stableswap :: update_asset_peg_source(
376376 RuntimeOrigin :: root( ) ,
377377 pool_id,
378378 asset_b, // Second asset
379379 new_peg_source. clone( ) ,
380- false , // don't preserve_price
381380 ) ) ;
382381
383382 // Check that only asset_b's peg source was updated
384383 let updated_peg_info = PoolPegs :: < Test > :: get ( pool_id) . unwrap ( ) ;
385384 assert_eq ! ( updated_peg_info. source[ 0 ] , PegSource :: Value ( ( 1 , 1 ) ) ) ; // asset_a unchanged
386385 assert_eq ! ( updated_peg_info. source[ 1 ] , new_peg_source) ; // asset_b updated
387386
388- // Check that only asset_b's price was updated
387+ // Check that both prices were preserved (not updated)
389388 assert_eq ! ( updated_peg_info. current[ 0 ] , initial_price_a) ; // asset_a price unchanged
390- assert_eq ! ( updated_peg_info. current[ 1 ] , ( 3 , 4 ) ) ; // asset_b price updated
389+ assert_eq ! ( updated_peg_info. current[ 1 ] , ( 2 , 2 ) ) ; // asset_b price preserved
391390
392391 // Check event was emitted
393392 System :: assert_last_event (
@@ -447,7 +446,6 @@ fn update_asset_peg_source_should_work_with_three_assets() {
447446 pool_id,
448447 asset_b,
449448 new_peg_source. clone( ) ,
450- false ,
451449 ) ) ;
452450
453451 // Check that only asset_b's peg source was updated
@@ -456,9 +454,9 @@ fn update_asset_peg_source_should_work_with_three_assets() {
456454 assert_eq ! ( updated_peg_info. source[ 1 ] , new_peg_source) ;
457455 assert_eq ! ( updated_peg_info. source[ 2 ] , PegSource :: Value ( ( 3 , 3 ) ) ) ;
458456
459- // Check that only asset_b's price was updated
460- assert_eq ! ( updated_peg_info. current[ 0 ] , ( 1 , 1 ) ) ;
461- assert_eq ! ( updated_peg_info. current[ 1 ] , ( 5 , 6 ) ) ;
462- assert_eq ! ( updated_peg_info. current[ 2 ] , ( 3 , 3 ) ) ;
457+ // Check that all prices were preserved (not updated)
458+ assert_eq ! ( updated_peg_info. current[ 0 ] , ( 1 , 1 ) ) ; // asset_a price preserved
459+ assert_eq ! ( updated_peg_info. current[ 1 ] , ( 2 , 2 ) ) ; // asset_b price preserved
460+ assert_eq ! ( updated_peg_info. current[ 2 ] , ( 3 , 3 ) ) ; // asset_c price preserved
463461 } ) ;
464462}
0 commit comments