Skip to content

Commit

Permalink
refactor: remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnordelo committed Aug 1, 2024
1 parent d8b88eb commit 97b4cac
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bump scarb to v2.7.0-rc.1 (#1025)
- Bump scarb to v2.7.0-rc.2 (#1052)
- Bump scarb to v2.7.0-rc.4 (#1064)
- Bump scarb to v2.7.0 (#1065)

## 0.15.0-rc.0 (2024-07-8)

Expand Down
3 changes: 0 additions & 3 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = 1
name = "openzeppelin"
version = "0.15.0-rc.0"
dependencies = [
<<<<<<< HEAD
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_governance",
Expand Down Expand Up @@ -96,8 +95,6 @@ dependencies = [
name = "openzeppelin_utils"
version = "0.15.0-rc.0"
dependencies = [
=======
>>>>>>> 8561d75fab0c8e1acfcf7a37d290db368ed6a01b
"snforge_std",
]

Expand Down
6 changes: 3 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ version.workspace = true
[workspace.package]
version = "0.15.0-rc.0"
edition = "2023_11"
cairo-version = "2.7.0-rc.3"
scarb-version = "2.7.0-rc.4"
cairo-version = "2.7.0"
scarb-version = "2.7.0"
authors = ["OpenZeppelin Community <[email protected]>"]
description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup"
documentation = "https://docs.openzeppelin.com/contracts-cairo"
Expand All @@ -36,7 +36,7 @@ keywords = [
]

[workspace.dependencies]
starknet = "2.7.0-rc.3"
starknet = "2.7.0"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.26.0" }

[dependencies]
Expand Down
10 changes: 5 additions & 5 deletions packages/presets/src/tests/test_erc20.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::integer::BoundedInt;
use core::num::traits::Bounded;
use core::num::traits::Zero;
use openzeppelin_access::tests::common::OwnableSpyHelpers;
use openzeppelin_presets::interfaces::erc20::{
Expand Down Expand Up @@ -206,13 +206,13 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() {
let (_, mut dispatcher) = setup_dispatcher();

start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.approve(SPENDER(), BoundedInt::max());
dispatcher.approve(SPENDER(), Bounded::MAX);

start_cheat_caller_address(dispatcher.contract_address, SPENDER());
dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE);

let allowance = dispatcher.allowance(OWNER(), SPENDER());
assert_eq!(allowance, BoundedInt::max(), "Should not decrease");
assert_eq!(allowance, Bounded::MAX, "Should not decrease");
}

#[test]
Expand Down Expand Up @@ -269,13 +269,13 @@ fn test_transferFrom() {
fn test_transferFrom_doesnt_consume_infinite_allowance() {
let (_, mut dispatcher) = setup_dispatcher();
start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.approve(SPENDER(), BoundedInt::max());
dispatcher.approve(SPENDER(), Bounded::MAX);

start_cheat_caller_address(dispatcher.contract_address, SPENDER());
dispatcher.transferFrom(OWNER(), RECIPIENT(), VALUE);

let allowance = dispatcher.allowance(OWNER(), SPENDER());
assert_eq!(allowance, BoundedInt::max(), "Should not decrease");
assert_eq!(allowance, Bounded::MAX, "Should not decrease");
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions packages/token/src/erc20/erc20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use starknet::ContractAddress;
/// for examples.
#[starknet::component]
pub mod ERC20Component {
use core::integer::BoundedInt;
use core::num::traits::Bounded;
use core::num::traits::Zero;
use openzeppelin_token::erc20::interface;
use starknet::ContractAddress;
Expand Down Expand Up @@ -427,7 +427,7 @@ pub mod ERC20Component {
amount: u256
) {
let current_allowance = self.ERC20_allowances.read((owner, spender));
if current_allowance != BoundedInt::max() {
if current_allowance != Bounded::MAX {
assert(current_allowance >= amount, Errors::INSUFFICIENT_ALLOWANCE);
self._approve(owner, spender, current_allowance - amount);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/token/src/tests/erc20/test_erc20.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::integer::BoundedInt;
use core::num::traits::Bounded;
use openzeppelin_token::erc20::ERC20Component::{Approval, Transfer};
use openzeppelin_token::erc20::ERC20Component::{ERC20CamelOnlyImpl, ERC20Impl};
use openzeppelin_token::erc20::ERC20Component::{ERC20MetadataImpl, InternalImpl};
Expand Down Expand Up @@ -264,13 +264,13 @@ fn test_transfer_from() {
fn test_transfer_from_doesnt_consume_infinite_allowance() {
let mut state = setup();
start_cheat_caller_address(test_address(), OWNER());
state.approve(SPENDER(), BoundedInt::max());
state.approve(SPENDER(), Bounded::MAX);

start_cheat_caller_address(test_address(), SPENDER());
state.transfer_from(OWNER(), RECIPIENT(), VALUE);

let allowance = state.allowance(OWNER(), SPENDER());
assert_eq!(allowance, BoundedInt::max());
assert_eq!(allowance, Bounded::MAX);
}

#[test]
Expand Down Expand Up @@ -331,13 +331,13 @@ fn test_transferFrom() {
fn test_transferFrom_doesnt_consume_infinite_allowance() {
let mut state = setup();
start_cheat_caller_address(test_address(), OWNER());
state.approve(SPENDER(), BoundedInt::max());
state.approve(SPENDER(), Bounded::MAX);

start_cheat_caller_address(test_address(), SPENDER());
state.transferFrom(OWNER(), RECIPIENT(), VALUE);

let allowance = state.allowance(OWNER(), SPENDER());
assert_eq!(allowance, BoundedInt::max());
assert_eq!(allowance, Bounded::MAX);
}

#[test]
Expand Down Expand Up @@ -393,13 +393,13 @@ fn test__spend_allowance_not_unlimited() {
#[test]
fn test__spend_allowance_unlimited() {
let mut state = setup();
state._approve(OWNER(), SPENDER(), BoundedInt::max());
state._approve(OWNER(), SPENDER(), Bounded::MAX);

let max_minus_one: u256 = BoundedInt::max() - 1;
let max_minus_one: u256 = Bounded::MAX - 1;
state._spend_allowance(OWNER(), SPENDER(), max_minus_one);

let allowance = state.allowance(OWNER(), SPENDER());
assert_eq!(allowance, BoundedInt::max());
assert_eq!(allowance, Bounded::MAX);
}

//
Expand Down
14 changes: 7 additions & 7 deletions packages/token/src/tests/erc20/test_erc20_votes.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::integer::BoundedInt;
use core::num::traits::Bounded;
use core::num::traits::Zero;
use openzeppelin_token::erc20::ERC20Component::InternalImpl as ERC20Impl;
use openzeppelin_token::erc20::extensions::ERC20VotesComponent::{
Expand Down Expand Up @@ -101,9 +101,9 @@ fn test_get_past_votes() {
trace.push('ts3', 0x333);

// Big numbers (high different from 0x0)
let big1: u256 = BoundedInt::<u128>::max().into() + 0x444;
let big2: u256 = BoundedInt::<u128>::max().into() + 0x666;
let big3: u256 = BoundedInt::<u128>::max().into() + 0x888;
let big1: u256 = Bounded::<u128>::MAX.into() + 0x444;
let big2: u256 = Bounded::<u128>::MAX.into() + 0x666;
let big3: u256 = Bounded::<u128>::MAX.into() + 0x888;
trace.push('ts4', big1);
trace.push('ts6', big2);
trace.push('ts8', big3);
Expand Down Expand Up @@ -135,9 +135,9 @@ fn test_get_past_total_supply() {
trace.push('ts3', 0x333);

// Big numbers (high different from 0x0)
let big1: u256 = BoundedInt::<u128>::max().into() + 0x444;
let big2: u256 = BoundedInt::<u128>::max().into() + 0x666;
let big3: u256 = BoundedInt::<u128>::max().into() + 0x888;
let big1: u256 = Bounded::<u128>::MAX.into() + 0x444;
let big2: u256 = Bounded::<u128>::MAX.into() + 0x666;
let big3: u256 = Bounded::<u128>::MAX.into() + 0x888;
trace.push('ts4', big1);
trace.push('ts6', big2);
trace.push('ts8', big3);
Expand Down
17 changes: 8 additions & 9 deletions packages/utils/src/structs/checkpoint.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl CheckpointStorePacking of StorePacking<Checkpoint, (felt252, felt252)> {

#[cfg(test)]
mod test {
use core::integer::BoundedInt;
use core::num::traits::Bounded;
use super::Checkpoint;
use super::CheckpointStorePacking;
use super::_2_POW_184;
Expand All @@ -208,15 +208,15 @@ mod test {

#[test]
fn test_pack_big_key_and_value() {
let key = BoundedInt::max();
let value = BoundedInt::max();
let key = Bounded::MAX;
let value = Bounded::MAX;
let checkpoint = Checkpoint { key, value };

let (key_and_low, high) = CheckpointStorePacking::pack(checkpoint);

let expected_key: u256 = (key_and_low.into() / _2_POW_184.into()) & KEY_MASK;
let expected_low: u256 = key_and_low.into() & LOW_MASK;
let expected_high: felt252 = BoundedInt::<u128>::max().into();
let expected_high: felt252 = Bounded::<u128>::MAX.into();

assert_eq!(key.into(), expected_key);
assert_eq!(value.low.into(), expected_low);
Expand All @@ -225,14 +225,13 @@ mod test {

#[test]
fn test_unpack_big_key_and_value() {
let key_and_low = BoundedInt::<u64>::max().into() * _2_POW_184
+ BoundedInt::<u128>::max().into();
let high = BoundedInt::<u128>::max().into();
let key_and_low = Bounded::<u64>::MAX.into() * _2_POW_184 + Bounded::<u128>::MAX.into();
let high = Bounded::<u128>::MAX.into();

let checkpoint = CheckpointStorePacking::unpack((key_and_low, high));

let expected_key: u64 = BoundedInt::max();
let expected_value: u256 = BoundedInt::max();
let expected_key: u64 = Bounded::MAX;
let expected_value: u256 = Bounded::MAX;

assert_eq!(checkpoint.key, expected_key);
assert_eq!(checkpoint.value, expected_value);
Expand Down
10 changes: 5 additions & 5 deletions src/tests/presets/test_erc20.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::integer::BoundedInt;
use core::num::traits::Bounded;
use core::num::traits::Zero;
use openzeppelin::presets::interfaces::erc20::{
ERC20UpgradeableABISafeDispatcher, ERC20UpgradeableABISafeDispatcherTrait
Expand Down Expand Up @@ -206,13 +206,13 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() {
let (_, mut dispatcher) = setup_dispatcher();

start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.approve(SPENDER(), BoundedInt::max());
dispatcher.approve(SPENDER(), Bounded::MAX);

start_cheat_caller_address(dispatcher.contract_address, SPENDER());
dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE);

let allowance = dispatcher.allowance(OWNER(), SPENDER());
assert_eq!(allowance, BoundedInt::max(), "Should not decrease");
assert_eq!(allowance, Bounded::MAX, "Should not decrease");
}

#[test]
Expand Down Expand Up @@ -269,13 +269,13 @@ fn test_transferFrom() {
fn test_transferFrom_doesnt_consume_infinite_allowance() {
let (_, mut dispatcher) = setup_dispatcher();
start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.approve(SPENDER(), BoundedInt::max());
dispatcher.approve(SPENDER(), Bounded::MAX);

start_cheat_caller_address(dispatcher.contract_address, SPENDER());
dispatcher.transferFrom(OWNER(), RECIPIENT(), VALUE);

let allowance = dispatcher.allowance(OWNER(), SPENDER());
assert_eq!(allowance, BoundedInt::max(), "Should not decrease");
assert_eq!(allowance, Bounded::MAX, "Should not decrease");
}

#[test]
Expand Down

0 comments on commit 97b4cac

Please sign in to comment.