diff --git a/src/lib.cairo b/src/lib.cairo index 4ea3cf2..5350462 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -52,6 +52,9 @@ mod systems { mod game_system; mod poker_hand_system; mod rage_system; + mod mock { + mod erc721_system; + } } #[cfg(test)] diff --git a/src/models/status/round/adventurer.cairo b/src/models/status/round/adventurer.cairo index f6bfec7..12a9ba2 100644 --- a/src/models/status/round/adventurer.cairo +++ b/src/models/status/round/adventurer.cairo @@ -1,10 +1,8 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; +use jokers_of_neon::models::data::adventurer::{AdventurerConsumed, AdventurerConsumedStore}; +use jokers_of_neon::utils::adventurer::get_adventurer_address; use openzeppelin_token::erc721::interface::{IERC721Dispatcher, IERC721DispatcherTrait}; -use jokers_of_neon::models::data::adventurer::{ - AdventurerConsumed, AdventurerConsumedStore -}; -use jokers_of_neon::utils::adventurer::get_adventurer_address; use starknet::{ContractAddress, get_caller_address, get_tx_info}; mod errors { @@ -14,9 +12,8 @@ mod errors { #[generate_trait] impl AdventurerImpl of AdventurerTrait { - fn use_adventurer(world: IWorldDispatcher, adventurer_id: u32) { - assert_adventurer_ownership(adventurer_id); + assert_adventurer_ownership(world, adventurer_id); let mut adventurer_consumed = AdventurerConsumedStore::get(world, adventurer_id); assert(!adventurer_consumed.consumed, errors::ADVENTURER_CONSUMED); adventurer_consumed.consumed = true; @@ -24,17 +21,16 @@ impl AdventurerImpl of AdventurerTrait { } } -fn assert_adventurer_ownership(token_id: u32) { - let owner = get_owner_of_adventurer(token_id); +fn assert_adventurer_ownership(world: IWorldDispatcher, token_id: u32) { + let owner = get_owner_of_adventurer(world, token_id); assert(owner == get_caller_address(), errors::NOT_TOKEN_OWNER); } -fn get_owner_of_adventurer(token_id: u32) -> ContractAddress { - let adventurer_address = get_adventurer_address(get_tx_info().unbox().chain_id); +fn get_owner_of_adventurer(world: IWorldDispatcher, token_id: u32) -> ContractAddress { + let adventurer_address = get_adventurer_address(world, get_tx_info().unbox().chain_id); let erc721_dispatcher = IERC721Dispatcher { contract_address: adventurer_address }; erc721_dispatcher.owner_of(token_id.into()) } - // fn _get_adventurer(self: @ContractState, token_id: u32) -> Adventurer { // let adventurer_address = utils::ADVENTURER_ADDRESS_MAINNET(); // let game_dispatcher = IGameDispatcher { contract_address: adventurer_address }; @@ -47,4 +43,5 @@ fn get_owner_of_adventurer(token_id: u32) -> ContractAddress { // health: adventurer.health, // rank_at_death: adventurer_meta.rank_at_death, // } -// } \ No newline at end of file +// } + diff --git a/src/models/status/round/beast.cairo b/src/models/status/round/beast.cairo index 70fc10e..06ff0e5 100644 --- a/src/models/status/round/beast.cairo +++ b/src/models/status/round/beast.cairo @@ -93,7 +93,6 @@ impl BeastImpl of BeastTrait { player_beast.energy -= game_mode_beast.cost_play; PlayerBeastStore::set(@player_beast, world); - if beast.current_health.is_zero() { let play_win_game_event = PlayWinGameEvent { player: get_caller_address(), game_id, level: game.level, player_score: 0 @@ -112,7 +111,7 @@ impl BeastImpl of BeastTrait { _ => Option::None }.unwrap(); IRageSystemDispatcher { contract_address: rage_system_address.try_into().unwrap() }.calculate(game.id); - // create_level(world, ref store, game); TODO: + // create_level(world, ref store, game); TODO: } else if player_beast.energy.is_zero() { _attack_beast(world, ref store, ref game, ref player_beast, ref beast, ref game_mode_beast); } else { diff --git a/src/systems/mock/erc721_system.cairo b/src/systems/mock/erc721_system.cairo new file mode 100644 index 0000000..5cab5cf --- /dev/null +++ b/src/systems/mock/erc721_system.cairo @@ -0,0 +1,14 @@ +#[dojo::interface] +trait IERC721System { + fn owner_of(ref world: IWorldDispatcher, token_id: u256) -> bool; +} + +#[dojo::contract] +mod erc721_system { + #[abi(embed_v0)] + impl ERC721Impl of super::IERC721System { + fn owner_of(ref world: IWorldDispatcher, token_id: u256) -> bool { + true + } + } +} diff --git a/src/tests/test_game_play_beast.cairo b/src/tests/test_game_play_beast.cairo index 3dba408..0fc991b 100644 --- a/src/tests/test_game_play_beast.cairo +++ b/src/tests/test_game_play_beast.cairo @@ -278,7 +278,7 @@ mod test_play_beast_special_cards { player_beast_after.energy == player_beast_before.energy - game_mode_beast.cost_play, 'wrong player energy' ); } -// #[test] + // #[test] // #[available_gas(30000000000000000)] // fn test_play_special_initial_advantage() { // let (world, systems) = setup::spawn_game(); @@ -286,15 +286,15 @@ mod test_play_beast_special_cards { // let mut game = mock_game(ref store, PLAYER()); // mock_round(ref store, @game, 300); -// // Mock special card + // // Mock special card // let special_cards_ids = array![SPECIAL_INITIAL_ADVANTAGE_ID]; // mock_special_cards(ref store, ref game, special_cards_ids); -// // Mock hand + // // Mock hand // let hand_cards_ids = array![ACE_CLUBS_ID, ACE_HEARTS_ID, ACE_DIAMONDS_ID, ACE_SPADES_ID]; // mock_current_hand_cards_ids(ref store, game.id, hand_cards_ids); -// set_contract_address(PLAYER()); + // set_contract_address(PLAYER()); // systems.game_system.play(game.id, array![0, 1, 2, 3], array![100, 100, 100, 100]); // // Four of a Kind - points: 60, multi: 7 // // points: 11 + 11 + 11 + 11 + 100 diff --git a/src/utils/adventurer.cairo b/src/utils/adventurer.cairo index a79b7e1..708015d 100644 --- a/src/utils/adventurer.cairo +++ b/src/utils/adventurer.cairo @@ -1,15 +1,22 @@ +use dojo::world::Resource::Contract; +use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; + use starknet::{ContractAddress, contract_address_const}; const MAINNET_CHAIN_ID: felt252 = 0x534e5f4d41494e; -fn get_adventurer_address(chain_id: felt252) -> ContractAddress { +fn get_adventurer_address(world: IWorldDispatcher, chain_id: felt252) -> ContractAddress { if chain_id == MAINNET_CHAIN_ID { ADVENTURER_ADDRESS_MAINNET() } else { - panic_with_felt252('Chain not supported') + let (_, erc721_system_address) = match world.resource(selector_from_tag!("jokers_of_neon-erc721_system")) { + Contract((class_hash, contract_address)) => Option::Some((class_hash, contract_address)), + _ => Option::None + }.unwrap(); + erc721_system_address } } fn ADVENTURER_ADDRESS_MAINNET() -> ContractAddress { contract_address_const::<0x018108b32cea514a78ef1b0e4a0753e855cdf620bc0565202c02456f618c4dc4>() -} \ No newline at end of file +}