Skip to content

Commit

Permalink
Migrate Ownable Dual Dispatcher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
immrsd committed Jul 2, 2024
1 parent 8254c53 commit 2febf8c
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions src/tests/access/test_dual_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock;
use openzeppelin::tests::mocks::ownable_mocks::{
CamelOwnableMock, CamelOwnablePanicMock, SnakeOwnableMock, SnakeOwnablePanicMock
};
use openzeppelin::tests::utils::common::declare_and_deploy;
use openzeppelin::tests::utils::constants::{OWNER, NEW_OWNER};
use openzeppelin::tests::utils;
use openzeppelin::utils::serde::SerializedAppend;
use starknet::testing::set_contract_address;
use snforge_std::start_cheat_caller_address;

//
// Setup
Expand All @@ -20,14 +20,14 @@ use starknet::testing::set_contract_address;
fn setup_snake() -> (DualCaseOwnable, IOwnableDispatcher) {
let mut calldata = array![];
calldata.append_serde(OWNER());
let target = utils::deploy(SnakeOwnableMock::TEST_CLASS_HASH, calldata);
let target = declare_and_deploy("SnakeOwnableMock", calldata);
(DualCaseOwnable { contract_address: target }, IOwnableDispatcher { contract_address: target })
}

fn setup_camel() -> (DualCaseOwnable, IOwnableCamelOnlyDispatcher) {
let mut calldata = array![];
calldata.append_serde(OWNER());
let target = utils::deploy(CamelOwnableMock::TEST_CLASS_HASH, calldata);
let target = declare_and_deploy("CamelOwnableMock", calldata);
(
DualCaseOwnable { contract_address: target },
IOwnableCamelOnlyDispatcher { contract_address: target }
Expand All @@ -36,13 +36,13 @@ fn setup_camel() -> (DualCaseOwnable, IOwnableCamelOnlyDispatcher) {

fn setup_non_ownable() -> DualCaseOwnable {
let calldata = array![];
let target = utils::deploy(NonImplementingMock::TEST_CLASS_HASH, calldata);
let target = declare_and_deploy("NonImplementingMock", calldata);
DualCaseOwnable { contract_address: target }
}

fn setup_ownable_panic() -> (DualCaseOwnable, DualCaseOwnable) {
let snake_target = utils::deploy(SnakeOwnablePanicMock::TEST_CLASS_HASH, array![]);
let camel_target = utils::deploy(CamelOwnablePanicMock::TEST_CLASS_HASH, array![]);
let snake_target = declare_and_deploy("SnakeOwnablePanicMock", array![]);
let camel_target = declare_and_deploy("CamelOwnablePanicMock", array![]);
(
DualCaseOwnable { contract_address: snake_target },
DualCaseOwnable { contract_address: camel_target }
Expand All @@ -66,14 +66,18 @@ fn test_dual_owner() {
}

#[test]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
#[should_panic(
expected: (
"Entry point selector 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0 not found in contract 0x036958e39c33afae916e4122aa060d535d9f24414e93789e90eb69ff894a0853",
)
)]
fn test_dual_no_owner() {
let dispatcher = setup_non_ownable();
dispatcher.owner();
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
#[should_panic(expected: ("Some error",))]
fn test_dual_owner_exists_and_panics() {
let (dispatcher, _) = setup_ownable_panic();
dispatcher.owner();
Expand All @@ -86,22 +90,26 @@ fn test_dual_owner_exists_and_panics() {
#[test]
fn test_dual_transfer_ownership() {
let (dispatcher, target) = setup_snake();
set_contract_address(OWNER());
start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.transfer_ownership(NEW_OWNER());

let current_owner = target.owner();
assert_eq!(current_owner, NEW_OWNER());
}

#[test]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
#[should_panic(
expected: (
"Entry point selector 0x02a3bb1eaa05b77c4b0eeee0116a3177c6d62319dd7149ae148185d9e09de74a not found in contract 0x036958e39c33afae916e4122aa060d535d9f24414e93789e90eb69ff894a0853",
)
)]
fn test_dual_no_transfer_ownership() {
let dispatcher = setup_non_ownable();
dispatcher.transfer_ownership(NEW_OWNER());
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
#[should_panic(expected: ("Some error",))]
fn test_dual_transfer_ownership_exists_and_panics() {
let (dispatcher, _) = setup_ownable_panic();
dispatcher.transfer_ownership(NEW_OWNER());
Expand All @@ -110,22 +118,26 @@ fn test_dual_transfer_ownership_exists_and_panics() {
#[test]
fn test_dual_renounce_ownership() {
let (dispatcher, target) = setup_snake();
set_contract_address(OWNER());
start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.renounce_ownership();

let current_owner = target.owner();
assert!(current_owner.is_zero());
}

#[test]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
#[should_panic(
expected: (
"Entry point selector 0x00052580a92c73f4428f1a260c5d768ef462b25955307de00f99957df119865d not found in contract 0x036958e39c33afae916e4122aa060d535d9f24414e93789e90eb69ff894a0853",
)
)]
fn test_dual_no_renounce_ownership() {
let dispatcher = setup_non_ownable();
dispatcher.renounce_ownership();
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
#[should_panic(expected: ("Some error",))]
fn test_dual_renounce_ownership_exists_and_panics() {
let (dispatcher, _) = setup_ownable_panic();
dispatcher.renounce_ownership();
Expand All @@ -136,36 +148,40 @@ fn test_dual_renounce_ownership_exists_and_panics() {
//

#[test]
#[ignore]
fn test_dual_transferOwnership() {
let (dispatcher, _) = setup_camel();
set_contract_address(OWNER());
start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.transfer_ownership(NEW_OWNER());

let current_owner = dispatcher.owner();
assert_eq!(current_owner, NEW_OWNER());
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
#[ignore]
#[should_panic(expected: ("Some error",))]
fn test_dual_transferOwnership_exists_and_panics() {
let (_, dispatcher) = setup_ownable_panic();
dispatcher.transfer_ownership(NEW_OWNER());
let (_, camel_dispatcher) = setup_ownable_panic();
camel_dispatcher.transfer_ownership(NEW_OWNER());
}

#[test]
#[ignore]
fn test_dual_renounceOwnership() {
let (dispatcher, _) = setup_camel();
set_contract_address(OWNER());
start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.renounce_ownership();

let current_owner = dispatcher.owner();
assert!(current_owner.is_zero());
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
#[ignore]
#[should_panic(expected: ("Some error",))]
fn test_dual_renounceOwnership_exists_and_panics() {
let (_, dispatcher) = setup_ownable_panic();
dispatcher.renounce_ownership();
let (_, camel_dispatcher) = setup_ownable_panic();
camel_dispatcher.renounce_ownership();
}

0 comments on commit 2febf8c

Please sign in to comment.