From a851372c64def973eedce7ee57e4d0689b774510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 6 Aug 2024 19:13:43 +0300 Subject: [PATCH 1/2] price-aggr: Remove require_paused from setPairDecimals --- contracts/price-aggregator/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/contracts/price-aggregator/src/lib.rs b/contracts/price-aggregator/src/lib.rs index 98b703f5..641daba8 100644 --- a/contracts/price-aggregator/src/lib.rs +++ b/contracts/price-aggregator/src/lib.rs @@ -377,8 +377,6 @@ 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 = TokenPair { from, to }; self.clear_submissions(&pair); From a5114a46eb0bc2bda2c4f4151b83a608b34eb225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 23 Aug 2024 12:24:31 +0300 Subject: [PATCH 2/2] price-aggregator: setPair require contract paused Added unit test --- contracts/price-aggregator/src/lib.rs | 6 ++- .../tests/price_aggregator_blackbox_test.rs | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/contracts/price-aggregator/src/lib.rs b/contracts/price-aggregator/src/lib.rs index 641daba8..31a1b149 100644 --- a/contracts/price-aggregator/src/lib.rs +++ b/contracts/price-aggregator/src/lib.rs @@ -377,7 +377,11 @@ pub trait PriceAggregator: #[only_owner] #[endpoint(setPairDecimals)] fn set_pair_decimals(&self, from: ManagedBuffer, to: ManagedBuffer, decimals: u8) { - 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(); +}