Skip to content

Commit

Permalink
fixed zero address
Browse files Browse the repository at this point in the history
  • Loading branch information
the-first-elder committed May 28, 2024
1 parent 2fbefe4 commit a898050
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions listings/applications/erc20/src/token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ mod tests {
ContractAddress, SyscallResultTrait, syscalls::deploy_syscall, get_caller_address,
contract_address_const
};
use core::num::traits::Zero;

use starknet::testing::{set_contract_address, set_account_contract_address};

Expand All @@ -246,7 +247,7 @@ mod tests {
#[test]
#[should_panic(expected: ('ERC20: mint to 0', 'CONSTRUCTOR_FAILED'))]
fn test_deploy_when_recipient_is_address_zero() {
let recipient: ContractAddress = get_caller_address();
let recipient: ContractAddress = Zero::zero();

let (contract_address, _) = deploy_syscall(
erc20::TEST_CLASS_HASH.try_into().unwrap(),
Expand All @@ -264,7 +265,7 @@ mod tests {
starknet::testing::pop_log(contract_address),
Option::Some(
Event::Transfer(
Transfer { from: get_caller_address(), to: recipient, value: initial_supply }
Transfer { from: Zero::zero(), to: recipient, value: initial_supply }
)
)
);
Expand Down Expand Up @@ -328,7 +329,7 @@ mod tests {
#[test]
#[should_panic(expected: ('ERC20: approve to 0', 'ENTRYPOINT_FAILED'))]
fn test_approval_spender_is_address_zero() {
let spender: ContractAddress = get_caller_address();
let spender: ContractAddress = Zero::zero();
let amount = 100;
let (dispatcher, _) = deploy();
dispatcher.approve(spender, amount);
Expand All @@ -349,7 +350,7 @@ mod tests {
starknet::testing::pop_log(contract_address),
Option::Some(
Event::Transfer(
Transfer { from: get_caller_address(), to: recipient, value: initial_supply }
Transfer { from: Zero::zero(), to: recipient, value: initial_supply }
)
)
);
Expand All @@ -363,7 +364,7 @@ mod tests {
#[test]
#[should_panic(expected: ('ERC20: approve to 0', 'ENTRYPOINT_FAILED'))]
fn test_should_increase_allowance_with_spender_zero_address() {
let spender = get_caller_address();
let spender = Zero::zero();
let amount = 100;
let (dispatcher, _) = deploy();
dispatcher.increase_allowance(spender, amount);
Expand Down Expand Up @@ -391,7 +392,7 @@ mod tests {
starknet::testing::pop_log(contract_address),
Option::Some(
Event::Transfer(
Transfer { from: get_caller_address(), to: recipient, value: initial_supply }
Transfer { from: Zero::zero(), to: recipient, value: initial_supply }
)
)
);
Expand All @@ -410,7 +411,7 @@ mod tests {
#[test]
#[should_panic(expected: ('ERC20: approve to 0', 'ENTRYPOINT_FAILED'))]
fn test_should_decrease_allowance_with_spender_zero_address() {
let spender = get_caller_address();
let spender = Zero::zero();
let amount = 100;
let (dispatcher, _) = deploy();
dispatcher.decrease_allowance(spender, amount);
Expand Down Expand Up @@ -439,7 +440,7 @@ mod tests {
starknet::testing::pop_log(contract_address),
Option::Some(
Event::Transfer(
Transfer { from: get_caller_address(), to: recipient, value: initial_supply }
Transfer { from: Zero::zero(), to: recipient, value: initial_supply }
)
)
);
Expand Down Expand Up @@ -469,7 +470,7 @@ mod tests {
#[should_panic]
fn test_transfer_when_recipient_is_address_zero() {
let caller = contract_address_const::<'caller'>();
let reciever = get_caller_address();
let reciever = Zero::zero();
let amount = 100;
let (dispatcher, _) = deploy();
set_contract_address(caller);
Expand All @@ -490,9 +491,7 @@ mod tests {
assert_eq!(
starknet::testing::pop_log(contract_address),
Option::Some(
Event::Transfer(
Transfer { from: get_caller_address(), to: caller, value: initial_supply }
)
Event::Transfer(Transfer { from: Zero::zero(), to: caller, value: initial_supply })
)
);

Expand All @@ -507,7 +506,7 @@ mod tests {
#[should_panic(expected: ('ERC20: transfer from 0', 'ENTRYPOINT_FAILED'))]
#[should_panic]
fn test_transferFrom_when_sender_is_address_zero() {
let sender = get_caller_address();
let sender = Zero::zero();
let amount = 100;
let reciever = contract_address_const::<'spender'>();
let (dispatcher, _) = deploy();
Expand All @@ -519,7 +518,7 @@ mod tests {
#[should_panic]
fn test_transferFrom_when_recipient_is_address_zero() {
let caller = contract_address_const::<'caller'>();
let reciever = get_caller_address();
let reciever = Zero::zero();
let amount = 100;
let (dispatcher, _) = deploy();
set_contract_address(caller);
Expand All @@ -541,9 +540,7 @@ mod tests {
assert_eq!(
starknet::testing::pop_log(contract_address),
Option::Some(
Event::Transfer(
Transfer { from: get_caller_address(), to: caller, value: initial_supply }
)
Event::Transfer(Transfer { from: Zero::zero(), to: caller, value: initial_supply })
)
);

Expand Down

0 comments on commit a898050

Please sign in to comment.