diff --git a/token/src/components/tests/mocks/erc20/erc20_allowance_mock.cairo b/token/src/components/tests/mocks/erc20/erc20_allowance_mock.cairo index 5dbbf617..b83e7963 100644 --- a/token/src/components/tests/mocks/erc20/erc20_allowance_mock.cairo +++ b/token/src/components/tests/mocks/erc20/erc20_allowance_mock.cairo @@ -9,12 +9,6 @@ mod erc20_allowance_mock { #[abi(embed_v0)] impl ERC20AllowanceImpl = erc20_allowance_component::ERC20AllowanceImpl; - #[abi(embed_v0)] - impl ERC20SafeAllowanceImpl = - erc20_allowance_component::ERC20SafeAllowanceImpl; - #[abi(embed_v0)] - impl ERC20SafeAllowanceCamelImpl = - erc20_allowance_component::ERC20SafeAllowanceCamelImpl; impl ERC20AllowanceInternalImpl = erc20_allowance_component::InternalImpl; diff --git a/token/src/components/tests/token/erc20/test_erc20_allowance.cairo b/token/src/components/tests/token/erc20/test_erc20_allowance.cairo index e16e045b..ffe0c424 100644 --- a/token/src/components/tests/token/erc20/test_erc20_allowance.cairo +++ b/token/src/components/tests/token/erc20/test_erc20_allowance.cairo @@ -12,7 +12,7 @@ use token::components::token::erc20::erc20_allowance::{ }; use token::components::token::erc20::erc20_allowance::erc20_allowance_component; use token::components::token::erc20::erc20_allowance::erc20_allowance_component::{ - Approval, ERC20AllowanceImpl, ERC20SafeAllowanceImpl, ERC20SafeAllowanceCamelImpl, InternalImpl + Approval, ERC20AllowanceImpl, InternalImpl }; use token::components::tests::mocks::erc20::erc20_allowance_mock::erc20_allowance_mock; use token::components::tests::mocks::erc20::erc20_allowance_mock::erc20_allowance_mock::world_dispatcherContractMemberStateTrait; @@ -91,34 +91,6 @@ fn test_erc20_allowance_approve_to_zero() { state.erc20_allowance.approve(ZERO(), VALUE); } - -// -// update_allowance (increase_allowance, decrease_allowance) -// - -#[test] -#[available_gas(100000000)] -fn test_erc20_allowance_update_allowance() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - - state.erc20_allowance.approve(SPENDER(), VALUE); - utils::drop_event(ZERO()); - - state.erc20_allowance.update_allowance(OWNER(), SPENDER(), 0, SUPPLY); - assert( - state.erc20_allowance.allowance(OWNER(), SPENDER()) == VALUE + SUPPLY, - 'should be VALUE+SUPPLY' - ); - assert_only_event_approval(ZERO(), OWNER(), SPENDER(), VALUE + SUPPLY); - - state.erc20_allowance.update_allowance(OWNER(), SPENDER(), VALUE, 0); - assert(state.erc20_allowance.allowance(OWNER(), SPENDER()) == SUPPLY, 'should be SUPPLY'); - assert_only_event_approval(ZERO(), OWNER(), SPENDER(), SUPPLY); -} - - // // spend_allowance // @@ -140,168 +112,3 @@ fn test_erc20_allowance_spend_allowance() { ); assert_only_event_approval(ZERO(), OWNER(), SPENDER(), SUPPLY - VALUE); } - -#[test] -#[available_gas(100000000)] -fn test_erc20_allowance_spend_allowance_with_max_allowance() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - - state.erc20_allowance.approve(SPENDER(), BoundedInt::max()); - utils::drop_event(ZERO()); - - state.erc20_allowance.spend_allowance(OWNER(), SPENDER(), VALUE); - assert( - state.erc20_allowance.allowance(OWNER(), SPENDER()) == BoundedInt::max(), - 'should be BoundedInt::max()' - ); - - utils::assert_no_events_left(ZERO()); -} - - -// -// increase_allowance & increaseAllowance -// - -#[test] -#[available_gas(25000000)] -fn test_erc20_allowance_increase_allowance() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - state.erc20_allowance.approve(SPENDER(), VALUE); - utils::drop_event(ZERO()); - - assert(state.erc20_allowance.increase_allowance(SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(ZERO(), OWNER(), SPENDER(), VALUE * 2); - assert( - state.erc20_allowance.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should be amount * 2' - ); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('ERC20: approve to 0',))] -fn test_erc20_allowance_increase_allowance_to_zero_address() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - state.erc20_allowance.increase_allowance(ZERO(), VALUE); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('ERC20: approve from 0',))] -fn test_erc20_allowance_increase_allowance_from_zero_address() { - let (world, mut state) = STATE(); - state.erc20_allowance.increase_allowance(SPENDER(), VALUE); -} - -#[test] -#[available_gas(25000000)] -fn test_erc20_allowance_increaseAllowance() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - state.erc20_allowance.approve(SPENDER(), VALUE); - utils::drop_event(ZERO()); - - assert(state.erc20_allowance.increaseAllowance(SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(ZERO(), OWNER(), SPENDER(), 2 * VALUE); - assert( - state.erc20_allowance.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should be amount * 2' - ); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('ERC20: approve to 0',))] -fn test_erc20_allowance_increaseAllowance_to_zero_address() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - state.erc20_allowance.increaseAllowance(ZERO(), VALUE); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('ERC20: approve from 0',))] -fn test_erc20_allowance_increaseAllowance_from_zero_address() { - let (world, mut state) = STATE(); - state.erc20_allowance.increaseAllowance(SPENDER(), VALUE); -} - -// -// decrease_allowance & decreaseAllowance -// - -#[test] -#[available_gas(25000000)] -fn test_erc20_allowance_decrease_allowance() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - state.erc20_allowance.approve(SPENDER(), VALUE); - utils::drop_event(ZERO()); - - assert(state.erc20_allowance.decrease_allowance(SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(ZERO(), OWNER(), SPENDER(), 0); - assert(state.erc20_allowance.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('u256_sub Overflow',))] -fn test_erc20_allowance_decrease_allowance_to_zero_address() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - state.erc20_allowance.decrease_allowance(ZERO(), VALUE); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('u256_sub Overflow',))] -fn test_erc20_allowance_decrease_allowance_from_zero_address() { - let (world, mut state) = STATE(); - state.erc20_allowance.decrease_allowance(SPENDER(), VALUE); -} - -#[test] -#[available_gas(25000000)] -fn test_erc20_allowance_decreaseAllowance() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - state.erc20_allowance.approve(SPENDER(), VALUE); - utils::drop_event(ZERO()); - - assert(state.erc20_allowance.decreaseAllowance(SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(ZERO(), OWNER(), SPENDER(), 0); - assert(state.erc20_allowance.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('u256_sub Overflow',))] -fn test_erc20_allowance_decreaseAllowance_to_zero_address() { - let (world, mut state) = STATE(); - - testing::set_caller_address(OWNER()); - state.erc20_allowance.decreaseAllowance(ZERO(), VALUE); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('u256_sub Overflow',))] -fn test_erc20_allowance_decreaseAllowance_from_zero_address() { - let (world, mut state) = STATE(); - state.erc20_allowance.decreaseAllowance(SPENDER(), VALUE); -} - diff --git a/token/src/components/tests/token/erc20/test_erc20_balance.cairo b/token/src/components/tests/token/erc20/test_erc20_balance.cairo index 5742efbb..4d8fe446 100644 --- a/token/src/components/tests/token/erc20/test_erc20_balance.cairo +++ b/token/src/components/tests/token/erc20/test_erc20_balance.cairo @@ -222,34 +222,6 @@ fn test_transfer_from() { // assert(erc20_balance_mock.total_supply() == SUPPLY, 'Total supply should not change'); } -#[test] -#[available_gas(25000000)] -fn test_transfer_from_doesnt_consume_infinite_allowance() { - let (world, mut erc20_balance_mock) = setup(); - - utils::impersonate(OWNER()); - erc20_balance_mock.approve(SPENDER(), BoundedInt::max()); - - utils::drop_all_events(erc20_balance_mock.contract_address); - utils::drop_all_events(world.contract_address); - - utils::impersonate(SPENDER()); - erc20_balance_mock.transfer_from(OWNER(), RECIPIENT(), VALUE); - - assert_only_event_transfer(erc20_balance_mock.contract_address, OWNER(), RECIPIENT(), VALUE); - - // drop StoreSetRecord ERC20BalanceModel x2 - utils::drop_event(world.contract_address); - utils::drop_event(world.contract_address); - assert_only_event_transfer(world.contract_address, OWNER(), RECIPIENT(), VALUE); - - assert( - erc20_balance_mock.allowance(OWNER(), SPENDER()) == BoundedInt::max(), - 'Allowance should not change' - ); -} - - #[test] #[available_gas(25000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] diff --git a/token/src/components/token/erc20/erc20_allowance.cairo b/token/src/components/token/erc20/erc20_allowance.cairo index b4102364..240719f0 100644 --- a/token/src/components/token/erc20/erc20_allowance.cairo +++ b/token/src/components/token/erc20/erc20_allowance.cairo @@ -25,20 +25,6 @@ trait IERC20Allowance { fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; } -#[starknet::interface] -trait IERC20SafeAllowance { - fn increase_allowance(ref self: TState, spender: ContractAddress, added_value: u256) -> bool; - fn decrease_allowance( - ref self: TState, spender: ContractAddress, subtracted_value: u256 - ) -> bool; -} - -#[starknet::interface] -trait IERC20SafeAllowanceCamel { - fn increaseAllowance(ref self: TState, spender: ContractAddress, addedValue: u256) -> bool; - fn decreaseAllowance(ref self: TState, spender: ContractAddress, subtractedValue: u256) -> bool; -} - /// /// ERC20Allowance Component /// @@ -46,8 +32,6 @@ trait IERC20SafeAllowanceCamel { mod erc20_allowance_component { use super::ERC20AllowanceModel; use super::IERC20Allowance; - use super::IERC20SafeAllowance; - use super::IERC20SafeAllowanceCamel; use integer::BoundedInt; use starknet::ContractAddress; use starknet::{get_contract_address, get_caller_address}; @@ -100,52 +84,6 @@ mod erc20_allowance_component { } } - #[embeddable_as(ERC20SafeAllowanceImpl)] - impl ERC20SafeAllowance< - TContractState, - +HasComponent, - +IWorldProvider, - +Drop - > of IERC20SafeAllowance> { - fn increase_allowance( - ref self: ComponentState, spender: ContractAddress, added_value: u256 - ) -> bool { - self.update_allowance(get_caller_address(), spender, 0, added_value); - true - } - - fn decrease_allowance( - ref self: ComponentState, - spender: ContractAddress, - subtracted_value: u256 - ) -> bool { - self.update_allowance(get_caller_address(), spender, subtracted_value, 0); - true - } - } - - #[embeddable_as(ERC20SafeAllowanceCamelImpl)] - impl ERC20SafeAllowanceCamel< - TContractState, - +HasComponent, - +IWorldProvider, - +Drop - > of IERC20SafeAllowanceCamel> { - fn increaseAllowance( - ref self: ComponentState, spender: ContractAddress, addedValue: u256 - ) -> bool { - self.increase_allowance(spender, addedValue) - } - - fn decreaseAllowance( - ref self: ComponentState, - spender: ContractAddress, - subtractedValue: u256 - ) -> bool { - self.decrease_allowance(spender, subtractedValue) - } - } - /// /// Internal /// @@ -179,20 +117,6 @@ mod erc20_allowance_component { self.emit_event(approval_event); } - fn update_allowance( - ref self: ComponentState, - owner: ContractAddress, - spender: ContractAddress, - subtract: u256, - add: u256 - ) { - let mut allowance = self.get_allowance(owner, spender); - // adding and subtracting is fewer steps than if - allowance.amount = allowance.amount - subtract; - allowance.amount = allowance.amount + add; - self.set_allowance(allowance); - } - // use in transfer_from fn spend_allowance( ref self: ComponentState, @@ -200,10 +124,9 @@ mod erc20_allowance_component { spender: ContractAddress, amount: u256 ) { - let current_allowance = self.get_allowance(owner, spender).amount; - if current_allowance != BoundedInt::max() { - self.update_allowance(owner, spender, amount, 0); - } + let mut allowance = self.get_allowance(owner, spender); + allowance.amount = allowance.amount - amount; + self.set_allowance(allowance); } fn emit_event, +Drop, +Clone>( diff --git a/token/src/erc20/erc20.cairo b/token/src/erc20/erc20.cairo index 198c24b1..034ecbc9 100644 --- a/token/src/erc20/erc20.cairo +++ b/token/src/erc20/erc20.cairo @@ -141,36 +141,6 @@ mod ERC20 { } } - #[abi(embed_v0)] - fn increase_allowance( - ref self: ContractState, spender: ContractAddress, added_value: u256 - ) -> bool { - self.update_allowance(get_caller_address(), spender, 0, added_value); - true - } - - #[abi(embed_v0)] - fn increaseAllowance( - ref self: ContractState, spender: ContractAddress, addedValue: u256 - ) -> bool { - increase_allowance(ref self, spender, addedValue) - } - - #[abi(embed_v0)] - fn decrease_allowance( - ref self: ContractState, spender: ContractAddress, subtracted_value: u256 - ) -> bool { - self.update_allowance(get_caller_address(), spender, subtracted_value, 0); - true - } - - #[abi(embed_v0)] - fn decreaseAllowance( - ref self: ContractState, spender: ContractAddress, subtractedValue: u256 - ) -> bool { - decrease_allowance(ref self, spender, subtractedValue) - } - // // Internal // @@ -216,20 +186,6 @@ mod ERC20 { get!(self.world(), (get_contract_address(), owner, spender), ERC20Allowance) } - fn update_allowance( - ref self: ContractState, - owner: ContractAddress, - spender: ContractAddress, - subtract: u256, - add: u256 - ) { - let mut allowance = self.get_allowance(owner, spender); - // adding and subtracting is fewer steps than if - allowance.amount = allowance.amount - subtract; - allowance.amount = allowance.amount + add; - self.set_allowance(allowance); - } - fn set_allowance(ref self: ContractState, allowance: ERC20Allowance) { assert(!allowance.owner.is_zero(), Errors::APPROVE_FROM_ZERO); assert(!allowance.spender.is_zero(), Errors::APPROVE_TO_ZERO); @@ -298,10 +254,9 @@ mod ERC20 { fn _spend_allowance( ref self: ContractState, owner: ContractAddress, spender: ContractAddress, amount: u256 ) { - let current_allowance = self.get_allowance(owner, spender).amount; - if current_allowance != BoundedInt::max() { - self.update_allowance(owner, spender, amount, 0); - } + let mut allowance = self.get_allowance(owner, spender); + allowance.amount = allowance.amount - amount; + self.set_allowance(allowance); } } } diff --git a/token/src/erc20/interface.cairo b/token/src/erc20/interface.cairo index 89939915..577ce7db 100644 --- a/token/src/erc20/interface.cairo +++ b/token/src/erc20/interface.cairo @@ -19,14 +19,6 @@ trait IERC20Metadata { fn decimals(self: @TState) -> u8; } -#[starknet::interface] -trait ISafeAllowance { - fn increase_allowance(ref self: TState, spender: ContractAddress, added_value: u256) -> bool; - fn decrease_allowance( - ref self: TState, spender: ContractAddress, subtracted_value: u256 - ) -> bool; -} - #[starknet::interface] trait IERC20Camel { fn totalSupply(self: @TState) -> u256; @@ -48,12 +40,6 @@ trait IERC20CamelOnly { ) -> bool; } -#[starknet::interface] -trait ISafeAllowanceCamel { - fn increaseAllowance(ref self: TState, spender: ContractAddress, addedValue: u256) -> bool; - fn decreaseAllowance(ref self: TState, spender: ContractAddress, subtractedValue: u256) -> bool; -} - #[starknet::interface] trait ERC20ABI { // IERC20 @@ -71,20 +57,10 @@ trait ERC20ABI { fn symbol(self: @TState) -> felt252; fn decimals(self: @TState) -> u8; - // IERC20SafeAllowance - fn increase_allowance(ref self: TState, spender: ContractAddress, added_value: u256) -> bool; - fn decrease_allowance( - ref self: TState, spender: ContractAddress, subtracted_value: u256 - ) -> bool; - // IERC20CamelOnly fn totalSupply(self: @TState) -> u256; fn balanceOf(self: @TState, account: ContractAddress) -> u256; fn transferFrom( ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 ) -> bool; - - // IERC20CamelSafeAllowance - fn increaseAllowance(ref self: TState, spender: ContractAddress, addedValue: u256) -> bool; - fn decreaseAllowance(ref self: TState, spender: ContractAddress, subtractedValue: u256) -> bool; } diff --git a/token/src/erc20/tests.cairo b/token/src/erc20/tests.cairo index 3f088e4b..a98f582b 100644 --- a/token/src/erc20/tests.cairo +++ b/token/src/erc20/tests.cairo @@ -256,22 +256,6 @@ fn test_transfer_from() { assert(ERC20Impl::total_supply(@state) == SUPPLY, 'Total supply should not change'); } -#[test] -#[available_gas(25000000)] -fn test_transfer_from_doesnt_consume_infinite_allowance() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20Impl::approve(ref state, SPENDER(), BoundedInt::max()); - - testing::set_caller_address(SPENDER()); - ERC20Impl::transfer_from(ref state, OWNER(), RECIPIENT(), VALUE); - - assert( - ERC20Impl::allowance(@state, OWNER(), SPENDER()) == BoundedInt::max(), - 'Allowance should not change' - ); -} - #[test] #[available_gas(25000000)] #[should_panic(expected: ('u256_sub Overflow',))] @@ -305,138 +289,6 @@ fn test_transfer_from_from_zero_address() { ERC20Impl::transfer_from(ref state, Zeroable::zero(), RECIPIENT(), VALUE); } -// -// increase_allowance & increaseAllowance -// - -#[test] -#[available_gas(25000000)] -fn test_increase_allowance() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20Impl::approve(ref state, SPENDER(), VALUE); - utils::drop_event(ZERO()); - - assert(ERC20::increase_allowance(ref state, SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(OWNER(), SPENDER(), VALUE * 2); - assert(ERC20Impl::allowance(@state, OWNER(), SPENDER()) == VALUE * 2, 'Should be amount * 2'); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('ERC20: approve to 0',))] -fn test_increase_allowance_to_zero_address() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20::increase_allowance(ref state, Zeroable::zero(), VALUE); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('ERC20: approve from 0',))] -fn test_increase_allowance_from_zero_address() { - let mut state = setup(); - ERC20::increase_allowance(ref state, SPENDER(), VALUE); -} - -#[test] -#[available_gas(25000000)] -fn test_increaseAllowance() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20Impl::approve(ref state, SPENDER(), VALUE); - utils::drop_event(ZERO()); - - assert(ERC20::increaseAllowance(ref state, SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(OWNER(), SPENDER(), 2 * VALUE); - assert(ERC20Impl::allowance(@state, OWNER(), SPENDER()) == VALUE * 2, 'Should be amount * 2'); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('ERC20: approve to 0',))] -fn test_increaseAllowance_to_zero_address() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20::increaseAllowance(ref state, Zeroable::zero(), VALUE); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('ERC20: approve from 0',))] -fn test_increaseAllowance_from_zero_address() { - let mut state = setup(); - ERC20::increaseAllowance(ref state, SPENDER(), VALUE); -} - -// -// decrease_allowance & decreaseAllowance -// - -#[test] -#[available_gas(25000000)] -fn test_decrease_allowance() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20Impl::approve(ref state, SPENDER(), VALUE); - utils::drop_event(ZERO()); - - assert(ERC20::decrease_allowance(ref state, SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(OWNER(), SPENDER(), 0); - assert(ERC20Impl::allowance(@state, OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('u256_sub Overflow',))] -fn test_decrease_allowance_to_zero_address() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20::decrease_allowance(ref state, Zeroable::zero(), VALUE); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('u256_sub Overflow',))] -fn test_decrease_allowance_from_zero_address() { - let mut state = setup(); - ERC20::decrease_allowance(ref state, SPENDER(), VALUE); -} - -#[test] -#[available_gas(25000000)] -fn test_decreaseAllowance() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20Impl::approve(ref state, SPENDER(), VALUE); - utils::drop_event(ZERO()); - - assert(ERC20::decreaseAllowance(ref state, SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(OWNER(), SPENDER(), 0); - assert(ERC20Impl::allowance(@state, OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('u256_sub Overflow',))] -fn test_decreaseAllowance_to_zero_address() { - let mut state = setup(); - testing::set_caller_address(OWNER()); - ERC20::decreaseAllowance(ref state, Zeroable::zero(), VALUE); -} - -#[test] -#[available_gas(25000000)] -#[should_panic(expected: ('u256_sub Overflow',))] -fn test_decreaseAllowance_from_zero_address() { - let mut state = setup(); - ERC20::decreaseAllowance(ref state, SPENDER(), VALUE); -} - // // _spend_allowance // @@ -458,21 +310,6 @@ fn test__spend_allowance_not_unlimited() { ); } -#[test] -#[available_gas(25000000)] -fn test__spend_allowance_unlimited() { - let mut state = setup(); - InternalImpl::_approve(ref state, OWNER(), SPENDER(), BoundedInt::max()); - - let max_minus_one: u256 = BoundedInt::max() - 1; - InternalImpl::_spend_allowance(ref state, OWNER(), SPENDER(), max_minus_one); - - assert( - ERC20Impl::allowance(@state, OWNER(), SPENDER()) == BoundedInt::max(), - 'Allowance should not change' - ); -} - // // _mint // diff --git a/token/src/presets/erc20/bridgeable.cairo b/token/src/presets/erc20/bridgeable.cairo index 56a85061..ce647d46 100644 --- a/token/src/presets/erc20/bridgeable.cairo +++ b/token/src/presets/erc20/bridgeable.cairo @@ -37,16 +37,6 @@ trait IERC20BridgeablePreset { fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; - // IERC20SafeAllowance - fn decrease_allowance( - ref self: TState, spender: ContractAddress, subtracted_value: u256 - ) -> bool; - fn increase_allowance(ref self: TState, spender: ContractAddress, added_value: u256) -> bool; - - // IERC20SafeAllowanceCamel - fn decreaseAllowance(ref self: TState, spender: ContractAddress, subtractedValue: u256) -> bool; - fn increaseAllowance(ref self: TState, spender: ContractAddress, addedValue: u256) -> bool; - // IERC20Bridgeable fn burn(ref self: TState, account: ContractAddress, amount: u256); fn l2_bridge_address(self: @TState,) -> ContractAddress; @@ -156,14 +146,6 @@ mod ERC20Bridgeable { impl ERC20AllowanceImpl = erc20_allowance_component::ERC20AllowanceImpl; - #[abi(embed_v0)] - impl ERC20SafeAllowanceImpl = - erc20_allowance_component::ERC20SafeAllowanceImpl; - - #[abi(embed_v0)] - impl ERC20SafeAllowanceCamelImpl = - erc20_allowance_component::ERC20SafeAllowanceCamelImpl; - #[abi(embed_v0)] impl ERC20BridgeableImpl = erc20_bridgeable_component::ERC20BridgeableImpl; diff --git a/token/src/presets/erc20/tests_bridgeable.cairo b/token/src/presets/erc20/tests_bridgeable.cairo index 0c3fe8a7..2ac4b3c6 100644 --- a/token/src/presets/erc20/tests_bridgeable.cairo +++ b/token/src/presets/erc20/tests_bridgeable.cairo @@ -26,8 +26,7 @@ use token::components::token::erc20::erc20_allowance::{ erc_20_allowance_model, ERC20AllowanceModel, }; use token::components::token::erc20::erc20_allowance::erc20_allowance_component::{ - Approval, ERC20AllowanceImpl, InternalImpl as ERC20AllownceInternalImpl, ERC20SafeAllowanceImpl, - ERC20SafeAllowanceCamelImpl + Approval, ERC20AllowanceImpl, InternalImpl as ERC20AllownceInternalImpl, }; use token::components::token::erc20::erc20_bridgeable::{ @@ -195,86 +194,6 @@ fn test_transfer_from() { assert(erc20_bridgeable.total_supply() == SUPPLY, 'Total supply should not change'); } -#[test] -#[available_gas(25000000)] -fn test_transfer_from_doesnt_consume_infinite_allowance() { - let (world, mut erc20_bridgeable) = setup(); - - utils::impersonate(OWNER()); - erc20_bridgeable.approve(SPENDER(), BoundedInt::max()); - - utils::drop_all_events(erc20_bridgeable.contract_address); - utils::drop_all_events(world.contract_address); - - utils::impersonate(SPENDER()); - erc20_bridgeable.transfer_from(OWNER(), RECIPIENT(), VALUE); - - assert_only_event_transfer(erc20_bridgeable.contract_address, OWNER(), RECIPIENT(), VALUE); - - // drop StoreSetRecord ERC20BalanceModel x2 - utils::drop_event(world.contract_address); - utils::drop_event(world.contract_address); - assert_only_event_transfer(world.contract_address, OWNER(), RECIPIENT(), VALUE); - - assert( - erc20_bridgeable.allowance(OWNER(), SPENDER()) == BoundedInt::max(), - 'Allowance should not change' - ); -} - - -// -// increase_allowance -// - -#[test] -#[available_gas(25000000)] -fn test_increase_allowance() { - let (world, mut erc20_bridgeable) = setup(); - - utils::impersonate(OWNER()); - erc20_bridgeable.approve(SPENDER(), VALUE); - - utils::drop_all_events(erc20_bridgeable.contract_address); - utils::drop_all_events(world.contract_address); - - assert(erc20_bridgeable.increase_allowance(SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(erc20_bridgeable.contract_address, OWNER(), SPENDER(), VALUE * 2); - - // drop StoreSetRecord ERC20AllowanceModel - utils::drop_event(world.contract_address); - assert_only_event_approval(world.contract_address, OWNER(), SPENDER(), VALUE * 2); - - assert(erc20_bridgeable.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should be amount * 2'); -} - -// -// decrease_allowance -// - -#[test] -#[available_gas(25000000)] -fn test_decrease_allowance() { - let (world, mut erc20_bridgeable) = setup(); - - utils::impersonate(OWNER()); - erc20_bridgeable.approve(SPENDER(), VALUE); - - utils::drop_all_events(erc20_bridgeable.contract_address); - utils::drop_all_events(world.contract_address); - - assert(erc20_bridgeable.decrease_allowance(SPENDER(), VALUE), 'Should return true'); - - assert_only_event_approval(erc20_bridgeable.contract_address, OWNER(), SPENDER(), 0); - - // drop StoreSetRecord ERC20AllowanceModel - utils::drop_event(world.contract_address); - assert_only_event_approval(world.contract_address, OWNER(), SPENDER(), 0); - - assert(erc20_bridgeable.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); -} - // // bridgeable //