Skip to content

Commit

Permalink
feat: currency id verification (#39)
Browse files Browse the repository at this point in the history
* feat: currency id verification

Audit specification:
  - Add check of id != 0 in add_currency

* fix: test tag missing

---------

Co-authored-by: 0xevolve <Artevolve@yahoo.com>
  • Loading branch information
JordyRo1 and EvolveArt authored Oct 23, 2023
1 parent 3bee9c9 commit 49e7aca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/oracle/oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ mod Oracle {
// @param new_currency: the new currency to be added
fn add_currency(ref self: ContractState, new_currency: Currency) {
self.assert_only_admin();
assert(new_currency.id != 0, 'Currency id cannot be 0');
let existing_currency = self.oracle_currencies_storage.read(new_currency.id);
assert(existing_currency.id == 0, 'Currency already exists for key');
self.emit(Event::SubmittedCurrency(SubmittedCurrency { currency: new_currency }));
Expand Down
17 changes: 17 additions & 0 deletions src/tests/test_oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,23 @@ fn test_get_last_checkpoint_before_should_fail_if_timestamp_too_old() {
}


#[test]
#[should_panic(expected: ('Currency id cannot be 0', 'ENTRYPOINT_FAILED'))]
#[available_gas(2000000000)]
fn test_add_currency_should_fail_if_currency_id_null() {
let (publisher_registry, oracle) = setup();
oracle
.add_currency(
Currency {
id: 0,
decimals: 18_u32,
is_abstract_currency: false,
starknet_address: 0.try_into().unwrap(),
ethereum_address: 0.try_into().unwrap(),
}
);
}

#[test]
#[should_panic(expected: ('No base currency registered', 'ENTRYPOINT_FAILED'))]
#[available_gas(2000000000)]
Expand Down

0 comments on commit 49e7aca

Please sign in to comment.