diff --git a/contracts/price-aggregator/src/lib.rs b/contracts/price-aggregator/src/lib.rs index 98b703f5..31a1b149 100644 --- a/contracts/price-aggregator/src/lib.rs +++ b/contracts/price-aggregator/src/lib.rs @@ -377,9 +377,11 @@ pub trait PriceAggregator: #[only_owner] #[endpoint(setPairDecimals)] fn set_pair_decimals(&self, from: ManagedBuffer, to: ManagedBuffer, decimals: u8) { - self.require_paused(); - - self.pair_decimals(&from, &to).set(Some(decimals)); + let pair_decimals_mapper = self.pair_decimals(&from, &to); + if !pair_decimals_mapper.is_empty() { + self.require_paused(); + } + pair_decimals_mapper.set(Some(decimals)); let pair = TokenPair { from, to }; self.clear_submissions(&pair); } diff --git a/contracts/price-aggregator/tests/price_aggregator_blackbox_test.rs b/contracts/price-aggregator/tests/price_aggregator_blackbox_test.rs index b0e1f544..5c3def0d 100644 --- a/contracts/price-aggregator/tests/price_aggregator_blackbox_test.rs +++ b/contracts/price-aggregator/tests/price_aggregator_blackbox_test.rs @@ -126,6 +126,16 @@ impl PriceAggregatorTestState { .run(); } + fn pause_endpoint(&mut self) { + self.world + .tx() + .from(OWNER_ADDRESS) + .to(PRICE_AGGREGATOR_ADDRESS) + .typed(price_aggregator_proxy::PriceAggregatorProxy) + .pause_endpoint() + .run(); + } + fn submit(&mut self, from: &AddressValue, submission_timestamp: u64, price: u64) { self.world .tx() @@ -385,3 +395,30 @@ fn test_price_aggregator_slashing() { "only oracles allowed", ); } + +#[test] +fn test_set_decimals_pause() { + let mut state = PriceAggregatorTestState::new(); + state.deploy(); + + state.unpause_endpoint(); + + // First setPair can be done if contract is unpaused + state.set_pair_decimals(); + + // Second setPair cannot be done if contract is unpaused + state + .world + .tx() + .from(OWNER_ADDRESS) + .to(PRICE_AGGREGATOR_ADDRESS) + .typed(price_aggregator_proxy::PriceAggregatorProxy) + .set_pair_decimals(EGLD_TICKER, USD_TICKER, DECIMALS) + .returns(ExpectError(4, "Contract is not paused")) + .run(); + + state.pause_endpoint(); + + // setPair can be done while contract is paused + state.set_pair_decimals(); +}