Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update test for reject_land and update fn #115

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions land_registry/tests/test_land_register.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,149 @@ fn test_can_reject_land() {
stop_cheat_caller_address(contract_address);
}

#[test]
fn test_can_reject_land_by_inspector() {
let contract_address = deploy("LandRegistryContract");
let land_register_dispatcher = ILandRegistryDispatcher { contract_address };

// Set up test data
let owner_address = starknet::contract_address_const::<0x123>();
let inspector_address = starknet::contract_address_const::<0x456>();
let location = Location { latitude: 1, longitude: 2 };
let area = 1000;
let land_use = LandUse::Residential;

// Register land as owner
start_cheat_caller_address(contract_address, owner_address);
let land_id = land_register_dispatcher.register_land(location, area, land_use);
stop_cheat_caller_address(contract_address);

// Set inspector as owner
start_cheat_caller_address(contract_address, owner_address);
land_register_dispatcher.set_land_inspector(land_id, inspector_address);
stop_cheat_caller_address(contract_address);

// Reject land as inspector
start_cheat_caller_address(contract_address, inspector_address);

// Verify initial status
let land_before = land_register_dispatcher.get_land(land_id);
assert_eq!(land_before.status, LandStatus::Pending, "Should be pending before reject");

// Perform rejection
land_register_dispatcher.reject_land(land_id);

// Verify final status
let land_after = land_register_dispatcher.get_land(land_id);
assert_eq!(land_after.status, LandStatus::Rejected, "Should be rejected after");

stop_cheat_caller_address(contract_address);
}

#[test]
fn test_can_reject_land_by_owner() {
let contract_address = deploy("LandRegistryContract");
let land_register_dispatcher = ILandRegistryDispatcher { contract_address };

// Set up test data
let owner_address = starknet::contract_address_const::<0x123>();
let inspector_address = starknet::contract_address_const::<0x456>();
let location = Location { latitude: 1, longitude: 2 };
let area = 1000;
let land_use = LandUse::Residential;

// Register land as owner
start_cheat_caller_address(contract_address, owner_address);
let land_id = land_register_dispatcher.register_land(location, area, land_use);

// Verify initial status
let land_before = land_register_dispatcher.get_land(land_id);
assert_eq!(land_before.status, LandStatus::Pending, "Should be pending before reject");

// Owner rejects their own land
land_register_dispatcher.reject_land(land_id);

// Verify final status
let land_after = land_register_dispatcher.get_land(land_id);
assert_eq!(land_after.status, LandStatus::Rejected, "Should be rejected after");

stop_cheat_caller_address(contract_address);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only inspectors should be able to reject land

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, below is the process follow:

Register Land

Approve or Reject Land --- Inspector only

If appproved land, land nft is minted. Else, land is rejected. Only approved lands are valid and issued with NFts. Unapproved lands have the id as reference but don't have an associtated nft.


#[test]
#[should_panic(expected: ('Only inspector/owner can reject',))]
fn test_reject_land_by_unauthorized_user() {
let contract_address = deploy("LandRegistryContract");
let land_register_dispatcher = ILandRegistryDispatcher { contract_address };

// Set up test data
let owner_address = starknet::contract_address_const::<0x123>();
let unauthorized_address = starknet::contract_address_const::<0x789>();
let location = Location { latitude: 1, longitude: 2 };
let area = 1000;
let land_use = LandUse::Residential;

// Register land as owner
start_cheat_caller_address(contract_address, owner_address);
let land_id = land_register_dispatcher.register_land(location, area, land_use);
stop_cheat_caller_address(contract_address);

// Attempt to reject land as unauthorized user
start_cheat_caller_address(contract_address, unauthorized_address);
land_register_dispatcher.reject_land(land_id); // This should panic
stop_cheat_caller_address(contract_address);
}

#[test]
fn test_can_update_land() {
let contract_address = deploy("LandRegistryContract");
let land_register_dispatcher = ILandRegistryDispatcher { contract_address };

// Set up initial test data
let owner_address = starknet::contract_address_const::<0x123>();
let location = Location { latitude: 1, longitude: 2 };
let initial_area = 1000;
let initial_land_use = LandUse::Residential;

// Register land as owner
start_cheat_caller_address(contract_address, owner_address);
let land_id = land_register_dispatcher.register_land(location, initial_area, initial_land_use);

// Update data
let new_area = 1500;
let new_land_use = LandUse::Commercial;

// Update land
land_register_dispatcher.update_land(land_id, new_area, new_land_use);

// Verify updates
let updated_land = land_register_dispatcher.get_land(land_id);
assert(updated_land.area == new_area, 'Area not updated correctly');
assert(updated_land.land_use == new_land_use, 'Land use not updated correctly');

stop_cheat_caller_address(contract_address);
}

#[test]
#[should_panic(expected: ('Only owner can update land',))]
fn test_update_land_by_unauthorized_user() {
let contract_address = deploy("LandRegistryContract");
let land_register_dispatcher = ILandRegistryDispatcher { contract_address };

// Set up test data
let owner_address = starknet::contract_address_const::<0x123>();
let unauthorized_address = starknet::contract_address_const::<0x789>();
let location = Location { latitude: 1, longitude: 2 };
let area = 1000;
let land_use = LandUse::Residential;

// Register land as owner
start_cheat_caller_address(contract_address, owner_address);
let land_id = land_register_dispatcher.register_land(location, area, land_use);
stop_cheat_caller_address(contract_address);

// Attempt to update land as unauthorized user
start_cheat_caller_address(contract_address, unauthorized_address);
land_register_dispatcher.update_land(land_id, 1500, LandUse::Commercial); // This should panic
stop_cheat_caller_address(contract_address);
}
Loading