@@ -71,79 +71,31 @@ fn populate_oracle_for_dot() {
7171}
7272
7373#[ test]
74- fn remove_token_should_clear_dynamic_fees_storage ( ) {
74+ fn remove_token_should_clear_both_fees_and_oracle_entries ( ) {
7575 TestNet :: reset ( ) ;
7676
7777 Hydra :: execute_with ( || {
7878 // Arrange
7979 init_omnipool_with_oracle ( ) ;
8080 populate_oracle_for_dot ( ) ;
8181
82- // Verify dynamic fees are set for DOT
83- let dot_fees_before = hydradx_runtime:: DynamicFees :: current_fees ( DOT ) ;
84- assert ! (
85- dot_fees_before. is_some( ) ,
86- "DOT should have dynamic fees entries before removal"
87- ) ;
88-
89- // Get position and remove all liquidity
90- let position_id = 2 ; // DOT position (HDX=0, DAI=1, DOT=2)
91- let position = pallet_omnipool:: Pallet :: < hydradx_runtime:: Runtime > :: load_position (
92- position_id,
93- hydradx_runtime:: Omnipool :: protocol_account ( ) ,
94- )
95- . unwrap ( ) ;
96-
97- // Freeze the asset
98- assert_ok ! ( hydradx_runtime:: Omnipool :: set_asset_tradable_state(
99- RuntimeOrigin :: root( ) ,
100- DOT ,
101- Tradability :: FROZEN
102- ) ) ;
103-
104- // Sacrifice the position to remove all shares
105- assert_ok ! ( hydradx_runtime:: Omnipool :: sacrifice_position(
106- RuntimeOrigin :: signed( hydradx_runtime:: Omnipool :: protocol_account( ) ) ,
107- position_id
108- ) ) ;
109-
110- // Act - Remove token from omnipool
111- assert_ok ! ( hydradx_runtime:: Omnipool :: remove_token(
112- RuntimeOrigin :: root( ) ,
113- DOT ,
114- AccountId :: from( BOB ) ,
115- ) ) ;
116-
117- // Assert - Dynamic fees should be cleared
118- let dot_fees_after = hydradx_runtime:: DynamicFees :: current_fees ( DOT ) ;
82+ // Verify both dynamic fees and oracle entries exist
11983 assert ! (
120- dot_fees_after . is_none ( ) ,
121- "DOT dynamic fees should be cleared after token removal"
84+ hydradx_runtime :: DynamicFees :: current_fees ( DOT ) . is_some ( ) ,
85+ "DOT should have dynamic fees before removal"
12286 ) ;
12387
124- // Verify AssetFee storage is cleared
88+ // Verify AssetFee storage exists
12589 let asset_fee = pallet_dynamic_fees:: AssetFee :: < hydradx_runtime:: Runtime > :: get ( DOT ) ;
126- assert ! ( asset_fee. is_none ( ) , "DOT AssetFee storage should be cleared " ) ;
90+ assert ! ( asset_fee. is_some ( ) , "DOT AssetFee storage should exist before removal " ) ;
12791
128- // Verify AssetFeeConfiguration storage is cleared
92+ // Verify AssetFeeConfiguration storage exists
12993 let asset_fee_config = pallet_dynamic_fees:: AssetFeeConfiguration :: < hydradx_runtime:: Runtime > :: get ( DOT ) ;
13094 assert ! (
131- asset_fee_config. is_none ( ) ,
132- "DOT AssetFeeConfiguration storage should be cleared "
95+ asset_fee_config. is_some ( ) ,
96+ "DOT AssetFeeConfiguration storage should exist before removal "
13397 ) ;
134- } ) ;
135- }
13698
137- #[ test]
138- fn remove_token_should_clear_oracle_entries ( ) {
139- TestNet :: reset ( ) ;
140-
141- Hydra :: execute_with ( || {
142- // Arrange
143- init_omnipool_with_oracle ( ) ;
144- populate_oracle_for_dot ( ) ;
145-
146- // Verify oracle entries exist for DOT before removal
14799 let hub_asset = LRNA ;
148100 let assets = if DOT < hub_asset {
149101 ( DOT , hub_asset)
@@ -163,35 +115,53 @@ fn remove_token_should_clear_oracle_entries() {
163115 ) ;
164116 }
165117
166- // Get position and remove all liquidity
167- let position_id = 2 ; // DOT position
168- let position = pallet_omnipool:: Pallet :: < hydradx_runtime:: Runtime > :: load_position (
169- position_id,
170- hydradx_runtime:: Omnipool :: protocol_account ( ) ,
171- )
172- . unwrap ( ) ;
118+ // Verify whitelist entry exists
119+ let whitelist = pallet_ema_oracle:: WhitelistedAssets :: < hydradx_runtime:: Runtime > :: get ( ) ;
120+ assert ! (
121+ whitelist. contains( & ( * b"omnipool" , assets) ) ,
122+ "DOT should be in oracle whitelist before removal"
123+ ) ;
173124
174- // Freeze the asset
125+ // Act
126+ // Prepare for token removal
127+ let position_id = 2 ;
175128 assert_ok ! ( hydradx_runtime:: Omnipool :: set_asset_tradable_state(
176129 RuntimeOrigin :: root( ) ,
177130 DOT ,
178131 Tradability :: FROZEN
179132 ) ) ;
180133
181- // Sacrifice the position
182134 assert_ok ! ( hydradx_runtime:: Omnipool :: sacrifice_position(
183135 RuntimeOrigin :: signed( hydradx_runtime:: Omnipool :: protocol_account( ) ) ,
184136 position_id
185137 ) ) ;
186138
187- // Act - Remove token from omnipool
139+ // Remove token
188140 assert_ok ! ( hydradx_runtime:: Omnipool :: remove_token(
189141 RuntimeOrigin :: root( ) ,
190142 DOT ,
191143 AccountId :: from( BOB ) ,
192144 ) ) ;
193145
194- // Assert - Oracle entries should be cleared
146+ // Assert
147+ // Verify dynamic fees are cleared
148+ assert ! (
149+ hydradx_runtime:: DynamicFees :: current_fees( DOT ) . is_none( ) ,
150+ "DOT dynamic fees should be cleared"
151+ ) ;
152+
153+ // Verify AssetFee storage is cleared
154+ let asset_fee_after = pallet_dynamic_fees:: AssetFee :: < hydradx_runtime:: Runtime > :: get ( DOT ) ;
155+ assert ! ( asset_fee_after. is_none( ) , "DOT AssetFee storage should be cleared" ) ;
156+
157+ // Verify AssetFeeConfiguration storage is cleared
158+ let asset_fee_config_after = pallet_dynamic_fees:: AssetFeeConfiguration :: < hydradx_runtime:: Runtime > :: get ( DOT ) ;
159+ assert ! (
160+ asset_fee_config_after. is_none( ) ,
161+ "DOT AssetFeeConfiguration storage should be cleared"
162+ ) ;
163+
164+ // Verify oracle entries are cleared for all periods
195165 for period in supported_periods. iter ( ) {
196166 let oracle_entry =
197167 pallet_ema_oracle:: Oracles :: < hydradx_runtime:: Runtime > :: get ( ( * b"omnipool" , assets, period) ) ;
@@ -203,74 +173,19 @@ fn remove_token_should_clear_oracle_entries() {
203173 }
204174
205175 // Verify whitelist entry is removed
206- let whitelist = pallet_ema_oracle:: WhitelistedAssets :: < hydradx_runtime:: Runtime > :: get ( ) ;
176+ let whitelist_after = pallet_ema_oracle:: WhitelistedAssets :: < hydradx_runtime:: Runtime > :: get ( ) ;
207177 assert ! (
208- !whitelist . contains( & ( * b"omnipool" , assets) ) ,
178+ !whitelist_after . contains( & ( * b"omnipool" , assets) ) ,
209179 "DOT should be removed from oracle whitelist"
210180 ) ;
211- } ) ;
212- }
213-
214- #[ test]
215- fn remove_token_should_clear_both_fees_and_oracle_entries ( ) {
216- TestNet :: reset ( ) ;
217-
218- Hydra :: execute_with ( || {
219- // Arrange
220- init_omnipool_with_oracle ( ) ;
221- populate_oracle_for_dot ( ) ;
222181
223- // Verify both dynamic fees and oracle entries exist
182+ // Verify Accumulator storage is cleared
183+ let accumulator = pallet_ema_oracle:: Accumulator :: < hydradx_runtime:: Runtime > :: get ( ) ;
224184 assert ! (
225- hydradx_runtime :: DynamicFees :: current_fees ( DOT ) . is_some ( ) ,
226- "DOT should have dynamic fees before removal "
185+ !accumulator . contains_key ( & ( * b"omnipool" , assets ) ) ,
186+ "DOT should be removed from oracle accumulator "
227187 ) ;
228188
229- let hub_asset = LRNA ;
230- let assets = if DOT < hub_asset {
231- ( DOT , hub_asset)
232- } else {
233- ( hub_asset, DOT )
234- } ;
235-
236- let period = OraclePeriod :: LastBlock ;
237- let oracle_entry_before =
238- pallet_ema_oracle:: Oracles :: < hydradx_runtime:: Runtime > :: get ( ( * b"omnipool" , assets, period) ) ;
239- assert ! (
240- oracle_entry_before. is_some( ) ,
241- "Oracle entry should exist for DOT before removal"
242- ) ;
243-
244- // Prepare for token removal
245- let position_id = 2 ;
246- assert_ok ! ( hydradx_runtime:: Omnipool :: set_asset_tradable_state(
247- RuntimeOrigin :: root( ) ,
248- DOT ,
249- Tradability :: FROZEN
250- ) ) ;
251-
252- assert_ok ! ( hydradx_runtime:: Omnipool :: sacrifice_position(
253- RuntimeOrigin :: signed( hydradx_runtime:: Omnipool :: protocol_account( ) ) ,
254- position_id
255- ) ) ;
256-
257- // Act - Remove token
258- assert_ok ! ( hydradx_runtime:: Omnipool :: remove_token(
259- RuntimeOrigin :: root( ) ,
260- DOT ,
261- AccountId :: from( BOB ) ,
262- ) ) ;
263-
264- // Assert - Both should be cleared
265- assert ! (
266- hydradx_runtime:: DynamicFees :: current_fees( DOT ) . is_none( ) ,
267- "DOT dynamic fees should be cleared"
268- ) ;
269-
270- let oracle_entry_after =
271- pallet_ema_oracle:: Oracles :: < hydradx_runtime:: Runtime > :: get ( ( * b"omnipool" , assets, period) ) ;
272- assert ! ( oracle_entry_after. is_none( ) , "Oracle entry should be cleared for DOT" ) ;
273-
274189 // Verify the asset itself is removed
275190 let asset_state = hydradx_runtime:: Omnipool :: assets ( DOT ) ;
276191 assert ! ( asset_state. is_none( ) , "DOT asset should be removed from omnipool" ) ;
@@ -301,6 +216,7 @@ fn remove_token_should_not_affect_other_assets() {
301216 let hdx_oracle_before =
302217 pallet_ema_oracle:: Oracles :: < hydradx_runtime:: Runtime > :: get ( ( * b"omnipool" , hdx_assets, period) ) ;
303218
219+ // Act
304220 // Remove DOT
305221 let position_id = 2 ;
306222 assert_ok ! ( hydradx_runtime:: Omnipool :: set_asset_tradable_state(
@@ -320,7 +236,8 @@ fn remove_token_should_not_affect_other_assets() {
320236 AccountId :: from( BOB ) ,
321237 ) ) ;
322238
323- // Assert - Other assets' fees and oracle entries should remain
239+ // Assert
240+ // Other assets' fees and oracle entries should remain
324241 let hdx_fees_after = hydradx_runtime:: DynamicFees :: current_fees ( HDX ) ;
325242 let dai_fees_after = hydradx_runtime:: DynamicFees :: current_fees ( DAI ) ;
326243
0 commit comments