diff --git a/src/components/lockable/lockable.cairo b/src/components/lockable/lockable.cairo index d5bca72..c646e4a 100644 --- a/src/components/lockable/lockable.cairo +++ b/src/components/lockable/lockable.cairo @@ -47,8 +47,8 @@ pub mod LockableComponent { pub mod Errors { pub const UNAUTHORIZED: felt252 = 'Account: unauthorized'; pub const NOT_OWNER: felt252 = 'Account: Not Account Owner'; - pub const EXCEEDS_MAX_LOCK_TIME: felt252 = 'Lock time exceeded'; - pub const LOCKED_ACCOUNT: felt252 = 'Account Locked'; + pub const EXCEEDS_MAX_LOCK_TIME: felt252 = 'Account: Lock time exceeded'; + pub const LOCKED_ACCOUNT: felt252 = 'Account: Locked'; } diff --git a/src/components/presets/account_preset.cairo b/src/components/presets/account_preset.cairo index 2c15148..aa773af 100644 --- a/src/components/presets/account_preset.cairo +++ b/src/components/presets/account_preset.cairo @@ -66,7 +66,7 @@ pub mod AccountPreset { fn execute(ref self: ContractState, mut calls: Array) -> Array> { // cannot make this call when the account is lock let is_lock = self.lockable.is_lock(); - assert(is_lock != true, 'Account locked'); + assert(is_lock != true, 'Account: locked'); self.account._execute(calls) } } @@ -79,7 +79,7 @@ pub mod AccountPreset { fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { // cannot make this call when the account is lock let is_lock = self.lockable.is_lock(); - assert(is_lock != true, 'Account locked'); + assert(is_lock != true, 'Account: locked'); self.upgradeable._upgrade(new_class_hash); } } diff --git a/tests/test_lockable_component.cairo b/tests/test_lockable_component.cairo index fd36004..7f29eb2 100644 --- a/tests/test_lockable_component.cairo +++ b/tests/test_lockable_component.cairo @@ -90,8 +90,8 @@ fn test_lockable() { start_cheat_caller_address(contract_address, owner); let lockable_dispatcher = ILockableDispatcher { contract_address }; - - lockable_dispatcher.lock(40); + let lock_duration = 40_u64; + lockable_dispatcher.lock(lock_duration); let check_lock = lockable_dispatcher.is_lock(); assert(check_lock == true, 'Account Not Lock'); @@ -99,7 +99,7 @@ fn test_lockable() { } #[test] -#[should_panic(expected: ('Account locked',))] +#[should_panic(expected: ('Account: locked',))] fn test_execute_should_fail_when_locked() { let (contract_address, _) = __setup__(); let acct_dispatcher = IAccountDispatcher { contract_address: contract_address }; @@ -131,7 +131,7 @@ fn test_execute_should_fail_when_locked() { } #[test] -#[should_panic(expected: ('Account locked',))] +#[should_panic(expected: ('Account: locked',))] fn test_upgrade_should_fail_when_locked() { let (contract_address, _) = __setup__(); let acct_dispatcher = IAccountDispatcher { contract_address: contract_address }; @@ -151,22 +151,39 @@ fn test_upgrade_should_fail_when_locked() { start_cheat_caller_address(contract_address, owner); dispatcher.upgrade(new_class_hash); } +#[test] +#[should_panic(expected: ('Account: Locked',))] +fn test_locking_should_fail_if_already_locked() { + let (contract_address, _) = __setup__(); + let acct_dispatcher = IAccountDispatcher { contract_address: contract_address }; + + let owner = acct_dispatcher.owner(); + + start_cheat_caller_address(contract_address, owner); + + let lockable_dispatcher = ILockableDispatcher { contract_address }; + // First Lock + let lock_duration_one = 40_u64; + lockable_dispatcher.lock(lock_duration_one); + // Second lock + let lock_duration_two = 60_u64; + lockable_dispatcher.lock(lock_duration_two); +} #[test] #[should_panic(expected: ('Account: unauthorized',))] fn test_locking_should_fail_if_not_owner() { let (contract_address, _) = __setup__(); - let acct_dispatcher = IAccountDispatcher { contract_address: contract_address }; start_cheat_caller_address(contract_address, ACCOUNT2.try_into().unwrap()); let lockable_dispatcher = ILockableDispatcher { contract_address }; - - lockable_dispatcher.lock(40); + let lock_duration = 40_u64; + lockable_dispatcher.lock(lock_duration); } #[test] -#[should_panic(expected: ('Lock time exceeded',))] +#[should_panic(expected: ('Account: Lock time exceeded',))] fn test_should_fail_for_greater_than_a_year_lock_time() { let (contract_address, _) = __setup__(); let acct_dispatcher = IAccountDispatcher { contract_address: contract_address };