Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/guild/guild.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ pub mod Guild {
self.guild.ponzi_buy_land(land_location, token_for_sale, sell_price, amount_to_stake);
}

fn ponzi_sell_land(ref self: ContractState, land_location: u16) {
self.guild.ponzi_sell_land(land_location);
}

fn ponzi_set_price(ref self: ContractState, land_location: u16, new_price: u256) {
self.guild.ponzi_set_price(land_location, new_price);
}
Expand Down
12 changes: 12 additions & 0 deletions src/guild/guild_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,18 @@ pub mod GuildComponent {
.buy(land_location, token_for_sale, sell_price, amount_to_stake);
}

fn ponzi_sell_land(ref self: ComponentState<TContractState>, land_location: u16) {
let caller = get_caller_address();
self.check_permission(caller, ActionType::PONZI_SELL_LAND, 0);

let config = self.plugins.read('ponziland');
assert!(config.target_contract != Zero::zero(), "{}", Errors::PONZILAND_NOT_REGISTERED);
assert!(config.enabled, "{}", Errors::PLUGIN_DISABLED);

IPonziLandActionsDispatcher { contract_address: config.target_contract }
.sell(land_location);
}

fn ponzi_set_price(
ref self: ComponentState<TContractState>, land_location: u16, new_price: u256,
) {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/guild.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub trait IGuild<TState> {
sell_price: u256,
amount_to_stake: u256,
);
fn ponzi_sell_land(ref self: TState, land_location: u16);
fn ponzi_set_price(ref self: TState, land_location: u16, new_price: u256);
fn ponzi_claim_yield(ref self: TState, land_location: u16);
fn ponzi_increase_stake(ref self: TState, land_location: u16, amount_to_stake: u256);
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/ponziland.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub trait IPonziLandActions<TState> {
sell_price: u256,
amount_to_stake: u256,
);
fn sell(ref self: TState, land_location: u16);
fn increase_price(ref self: TState, land_location: u16, new_price: u256);
fn claim(ref self: TState, land_location: u16);
fn increase_stake(ref self: TState, land_location: u16, amount_to_stake: u256);
Expand Down
12 changes: 12 additions & 0 deletions src/mocks/ponziland.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod PonziLandMock {
last_buy_price: u256,
last_buy_stake_amount: u256,
last_buy_token_for_sale: ContractAddress,
last_sell_location: u16,
last_claim_location: u16,
last_set_price_location: u16,
last_set_price_value: u256,
Expand Down Expand Up @@ -36,6 +37,12 @@ pub mod PonziLandMock {
self.call_count.write(self.call_count.read() + 1);
}

#[external(v0)]
fn sell(ref self: ContractState, land_location: u16) {
self.last_sell_location.write(land_location);
self.call_count.write(self.call_count.read() + 1);
}

#[external(v0)]
fn increase_price(ref self: ContractState, land_location: u16, new_price: u256) {
self.last_set_price_location.write(land_location);
Expand Down Expand Up @@ -77,6 +84,11 @@ pub mod PonziLandMock {
self.last_buy_location.read()
}

#[external(v0)]
fn get_last_sell_location(self: @ContractState) -> u16 {
self.last_sell_location.read()
}

#[external(v0)]
fn get_last_set_price_location(self: @ContractState) -> u16 {
self.last_set_price_location.read()
Expand Down
40 changes: 40 additions & 0 deletions tests/test_treasury.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,46 @@ fn test_get_guild_name_returns_name() {
assert!(view.get_guild_name() == 'TreasuryGuild');
}

#[test]
fn test_ponzi_sell_land_with_permission() {
let (guild_address, guild, _) = deploy_guild();
let ponzi_address = deploy_ponziland();
register_ponziland_plugin(guild_address, guild, ponzi_address);
create_member_and_join(
guild_address, guild, ALICE(), member_role(ActionType::PONZI_SELL_LAND, 0),
);

start_cheat_caller_address(guild_address, ALICE());
guild.ponzi_sell_land(15);

assert!(ponzi_u32(ponzi_address, selector!("get_call_count")) == 1);
assert!(ponzi_u16(ponzi_address, selector!("get_last_sell_location")) == 15);
}

#[test]
#[should_panic]
fn test_ponzi_sell_land_fails_no_permission() {
let (guild_address, guild, _) = deploy_guild();
let ponzi_address = deploy_ponziland();
register_ponziland_plugin(guild_address, guild, ponzi_address);
create_member_and_join(guild_address, guild, ALICE(), member_role(0, 500));

start_cheat_caller_address(guild_address, ALICE());
guild.ponzi_sell_land(15);
}

#[test]
#[should_panic]
fn test_ponzi_sell_land_fails_plugin_not_registered() {
let (guild_address, guild, _) = deploy_guild();
create_member_and_join(
guild_address, guild, ALICE(), member_role(ActionType::PONZI_SELL_LAND, 0),
);

start_cheat_caller_address(guild_address, ALICE());
guild.ponzi_sell_land(15);
}

#[test]
fn test_view_functions_return_correct_data() {
let (guild_address, guild, view) = deploy_guild();
Expand Down
Loading