Skip to content

Commit

Permalink
Merge pull request #28 from keep-starknet-strange/feat/adds-test-for-…
Browse files Browse the repository at this point in the history
…ownable-comp

adds test for owner transfer
  • Loading branch information
ZackAttax authored Feb 3, 2025
2 parents 5d54192 + 7ecab27 commit 8c6ed5b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/utils/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pub fn OWNER() -> ContractAddress {
contract_address_const::<'OWNER'>()
}

pub fn NEW_OWNER() -> ContractAddress {
contract_address_const::<'NEW_OWNER'>()
}

pub fn MINTER() -> ContractAddress {
contract_address_const::<'MINTER'>()
}
Expand Down
39 changes: 38 additions & 1 deletion tests/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
mod utils;
use starknet::class_hash::class_hash_const;
use tokenized_bond::{TokenizedBond, ITokenizedBondDispatcher, ITokenizedBondDispatcherTrait};
use openzeppelin_access::ownable::OwnableComponent;
use openzeppelin_access::ownable::interface::{
IOwnableTwoStepDispatcher, IOwnableTwoStepDispatcherTrait,
};
use openzeppelin_upgrades::upgradeable::UpgradeableComponent;
use openzeppelin_security::pausable::PausableComponent;
use openzeppelin_token::erc1155::ERC1155Component;
use openzeppelin_token::erc1155::interface::{IERC1155Dispatcher, IERC1155DispatcherTrait};
use tokenized_bond::utils::constants::{
OWNER, MINTER, ZERO_ADDRESS, INTEREST_RATE, INTEREST_RATE_ZERO, MINT_AMOUNT, TOKEN_NAME,
TOKEN_ID, TIME_IN_THE_FUTURE, CUSTODIAL_FALSE, NOT_MINTER, NEW_MINTER, AMOUNT_TRANSFERRED,
TRANSFER_AMOUNT,
TRANSFER_AMOUNT, NEW_OWNER,
};
use snforge_std::{
EventSpyAssertionsTrait, spy_events, start_cheat_caller_address, stop_cheat_caller_address,
Expand Down Expand Up @@ -956,3 +960,36 @@ fn test_upgrade_not_owner() {
let (tokenized_bond, _minter) = setup_contract_with_minter();
tokenized_bond.upgrade(class_hash_const::<'UPGRADE'>());
}

#[test]
fn test_tokenized_bond_transfer_ownership() {
let mut spy = spy_events();
let (tokenized_bond, _minter) = setup_contract_with_minter();
let ownable = IOwnableTwoStepDispatcher { contract_address: tokenized_bond.contract_address };

assert(ownable.owner() == OWNER(), 'Initial wrong owner');

start_cheat_caller_address(tokenized_bond.contract_address, OWNER());
ownable.transfer_ownership(NEW_OWNER());
start_cheat_block_timestamp_global(get_block_timestamp() + 99999);

start_cheat_caller_address(tokenized_bond.contract_address, NEW_OWNER());
ownable.accept_ownership();

assert(ownable.owner() == NEW_OWNER(), 'transfer owner failed');

let expected_event = OwnableComponent::Event::OwnershipTransferred(
OwnableComponent::OwnershipTransferred { previous_owner: OWNER(), new_owner: NEW_OWNER() },
);
spy.assert_emitted(@array![(ownable.contract_address, expected_event)]);
}

#[test]
#[should_panic(expected: 'Caller is not the owner')]
fn test_tokenized_bond_transfer_ownership_not_owner() {
let (tokenized_bond, _minter) = setup_contract_with_minter();
let ownable = IOwnableTwoStepDispatcher { contract_address: tokenized_bond.contract_address };

ownable.transfer_ownership(NEW_OWNER());
assert(ownable.owner() == NEW_OWNER().into(), 'transfer owner failed');
}

0 comments on commit 8c6ed5b

Please sign in to comment.