Skip to content

Commit

Permalink
Merge pull request #100 from multiversx/remove-require-paused-price-a…
Browse files Browse the repository at this point in the history
…ggregator

price-aggr: Remove require_paused from setPairDecimals
  • Loading branch information
CostinCarabas authored Aug 23, 2024
2 parents bbfc474 + a5114a4 commit 714a45e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
8 changes: 5 additions & 3 deletions contracts/price-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
37 changes: 37 additions & 0 deletions contracts/price-aggregator/tests/price_aggregator_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}

0 comments on commit 714a45e

Please sign in to comment.