diff --git a/.DS_Store b/.DS_Store index c0ac5f3..0e695ae 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Scarb.lock b/Scarb.lock index b1ba5a8..aaff7bd 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -4,7 +4,7 @@ version = 1 [[package]] name = "cubit" version = "1.2.0" -source = "git+https://github.com/influenceth/cubit.git?rev=2ccb253#2ccb2536dffa3f15ebd38b755c1be65fde1eab0c" +source = "git+https://github.com/ametel01/cubit?rev=72784d8#72784d843630a9b216045631aca87b86d4bf5e10" [[package]] name = "nogame" @@ -18,8 +18,8 @@ dependencies = [ [[package]] name = "openzeppelin" -version = "0.7.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.7.0#61a2505fe0c0f19b5de2b3f8dedf421ba2cff657" +version = "0.8.0-beta.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?rev=4c95981#4c95981a7178e43730f152c85a92336dc6a22d62" [[package]] name = "snforge_std" diff --git a/Scarb.toml b/Scarb.toml index cc30b8f..e207939 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -6,10 +6,12 @@ authors = ["ametel01"] license = "MIT" [dependencies] -openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag = "v0.7.0" } -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.8.3" } +openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", rev = "4c95981" } +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.9.0" } xoroshiro = { git ="https://github.com/ametel01/xoroshiro-cairo.git" } -cubit = {git ="https://github.com/influenceth/cubit.git", rev="2ccb253"} +# cubit = {git ="https://github.com/influenceth/cubit.git", rev="2ccb253"} +cubit = {git ="https://github.com/ametel01/cubit", rev="72784d8"} + starknet = "^2.2.0" [[target.starknet-contract]] diff --git a/src/game/interface.cairo b/src/game/interface.cairo index f4f5412..992013e 100644 --- a/src/game/interface.cairo +++ b/src/game/interface.cairo @@ -1,9 +1,9 @@ use starknet::ContractAddress; use nogame::libraries::types::{ DefencesCost, DefencesLevels, EnergyCost, ERC20s, CompoundsCost, CompoundsLevels, ShipsLevels, - ShipsCost, TechLevels, TechsCost, Tokens, PlanetPosition, Cargo, Debris, Fleet, Mission + ShipsCost, TechLevels, TechsCost, Tokens, PlanetPosition, Cargo, Debris, Fleet, Mission, + HostileMission }; -use nogame::libraries::i128::I128Serde; #[starknet::interface] trait INoGame { @@ -54,9 +54,9 @@ trait INoGame { ref self: TState, f: Fleet, destination: PlanetPosition, is_debris_collection: bool ); // fn dock_fleet(ref self: TState, mission_id: u8); - fn attack_planet(ref self: TState, mission_id: u8); - fn recall_fleet(ref self: TState, mission_id: u8); - fn collect_debris(ref self: TState, mission_id: u8); + fn attack_planet(ref self: TState, mission_id: usize); + fn recall_fleet(ref self: TState, mission_id: usize); + fn collect_debris(ref self: TState, mission_id: usize); // View functions fn get_owner(self: @TState) -> ContractAddress; fn get_token_addresses(self: @TState) -> Tokens; @@ -83,8 +83,8 @@ trait INoGame { fn get_defences_levels(self: @TState, planet_id: u16) -> DefencesLevels; fn get_defences_cost(self: @TState) -> DefencesCost; fn is_noob_protected(self: @TState, planet1_id: u16, planet2_id: u16) -> bool; - fn get_mission_details(self: @TState, planet_id: u16, mission_id: u8) -> Mission; - fn get_hostile_missions(self: @TState, planet_id: u16) -> (PlanetPosition, u32); + fn get_mission_details(self: @TState, planet_id: u16, mission_id: usize) -> Mission; + fn get_hostile_missions(self: @TState, planet_id: u16) -> Array; fn get_active_missions(self: @TState, planet_id: u16) -> Array; fn get_travel_time( self: @TState, diff --git a/src/game/main.cairo b/src/game/main.cairo index 7a32080..8a7f095 100644 --- a/src/game/main.cairo +++ b/src/game/main.cairo @@ -15,7 +15,8 @@ mod NoGame { use nogame::libraries::types::{ ETH_ADDRESS, BANK_ADDRESS, E18, DefencesCost, DefencesLevels, EnergyCost, ERC20s, CompoundsCost, CompoundsLevels, ShipsLevels, ShipsCost, TechLevels, TechsCost, Tokens, - PlanetPosition, Debris, Mission, Fleet, MAX_NUMBER_OF_PLANETS, _0_05, PRICE, DAY + PlanetPosition, Debris, Mission, HostileMission, Fleet, MAX_NUMBER_OF_PLANETS, _0_05, PRICE, + DAY }; use nogame::libraries::compounds::Compounds; use nogame::libraries::defences::Defences; @@ -23,8 +24,8 @@ mod NoGame { use nogame::libraries::fleet; use nogame::libraries::research::Lab; use nogame::token::erc20::{INGERC20DispatcherTrait, INGERC20Dispatcher}; - use nogame::token::erc721::{INGERC721DispatcherTrait, INGERC721Dispatcher}; - use nogame::libraries::i128::{I128Serde, to_signed}; + use nogame::token::erc721::{IERC721NoGameDispatcherTrait, IERC721NoGameDispatcher}; + use nogame::libraries::i128::{to_signed}; use nogame::libraries::auction::{LinearVRGDA, LinearVRGDATrait}; @@ -45,7 +46,7 @@ mod NoGame { resources_spent: LegacyMap::, last_active: LegacyMap::, // Tokens. - erc721: INGERC721Dispatcher, + erc721: IERC721NoGameDispatcher, steel: INGERC20Dispatcher, quartz: INGERC20Dispatcher, tritium: INGERC20Dispatcher, @@ -86,9 +87,10 @@ mod NoGame { astral_available: LegacyMap::, plasma_available: LegacyMap::, // Fleet - active_missions: LegacyMap::<(u16, u8), Mission>, - active_missions_len: LegacyMap, - hostile_missions: LegacyMap, + active_missions: LegacyMap::<(u16, u32), Mission>, + active_missions_len: LegacyMap, + hostile_missions: LegacyMap<(u16, u32), HostileMission>, + hostile_missions_len: LegacyMap, } #[event] @@ -136,7 +138,7 @@ mod NoGame { ) { // NOTE: uncomment the following after testing with katana. assert(get_caller_address() == self.owner.read(), 'caller is not owner'); - self.erc721.write(INGERC721Dispatcher { contract_address: erc721 }); + self.erc721.write(IERC721NoGameDispatcher { contract_address: erc721 }); self.steel.write(INGERC20Dispatcher { contract_address: steel }); self.quartz.write(INGERC20Dispatcher { contract_address: quartz }); self.tritium.write(INGERC20Dispatcher { contract_address: tritium }); @@ -156,7 +158,7 @@ mod NoGame { let number_of_planets = self.number_of_planets.read(); assert(number_of_planets <= MAX_NUMBER_OF_PLANETS, 'max number of planets'); let token_id = number_of_planets + 1; - self.erc721.read().mint(to: caller, token_id: token_id.into()); + self.erc721.read().mint(caller, token_id.into()); let position = self.calculate_planet_position(token_id); self.planet_position.write(token_id, position); self.position_to_planet_id.write(self.get_raw_from_position(position), token_id); @@ -656,7 +658,7 @@ mod NoGame { let travel_time = fleet::get_flight_time(speed, distance); // Check numeber of mission let active_missions = self.active_missions_len.read(planet_id); - assert(active_missions < techs.digital + 1, 'max active missions'); + assert(active_missions < techs.digital.into() + 1, 'max active missions'); // Pay for fuel let consumption = fleet::get_fuel_consumption(f, distance); let mut cost: ERC20s = Default::default(); @@ -672,27 +674,25 @@ mod NoGame { mission.fleet = f; if is_debris_collection { mission.is_debris = true; + self.add_active_mission(planet_id, mission); } else { + let id = self.add_active_mission(planet_id, mission); mission.is_debris = false; - self - .hostile_missions - .write( - self.position_to_planet_id.read(self.get_raw_from_position(destination)), - ( - self.get_planet_position(planet_id), - fleet::calculate_number_of_ships(f, Zeroable::zero()) - ) - ); + let mut hostile_mission: HostileMission = Default::default(); + hostile_mission.origin = planet_id; + hostile_mission.id_at_origin = id; + hostile_mission.time_arrival = mission.time_arrival; + hostile_mission + .number_of_ships = fleet::calculate_number_of_ships(f, Zeroable::zero()); + + self.add_hostile_mission(destination_id, hostile_mission); } - self.active_missions.write((planet_id, active_missions + 1), mission); - self.active_missions_len.write(planet_id, active_missions + 1); // Write new fleet levels self.fleet_leave_planet(planet_id, f); - self.last_active.write(planet_id, get_block_timestamp()); } - fn attack_planet(ref self: ContractState, mission_id: u8) { + fn attack_planet(ref self: ContractState, mission_id: usize) { let origin = self.get_owned_planet(get_caller_address()); let mut mission = self.active_missions.read((origin, mission_id)); assert(!mission.is_zero(), 'the mission is empty'); @@ -722,27 +722,26 @@ mod NoGame { self.resources_timer.write(mission.destination, time_now); self .pay_resources_erc20( - self.erc721.read().owner_of(mission.destination.into()), loot_amount + self.erc721.read().ng_owner_of(mission.destination.into()), loot_amount ); self.receive_resources_erc20(get_caller_address(), loot_amount); self.fleet_return_planet(origin, mission.fleet); mission.fleet = f1; - self.active_missions_len.write(origin, self.active_missions_len.read(origin) - 1); self.active_missions.write((origin, mission_id), Zeroable::zero()); } - self.hostile_missions.write(mission.destination, (Zeroable::zero(), Zeroable::zero())); + self.remove_hostile_mission(mission.destination, mission_id); } - fn recall_fleet(ref self: ContractState, mission_id: u8) { + fn recall_fleet(ref self: ContractState, mission_id: usize) { let origin = self.get_owned_planet(get_caller_address()); let mission = self.active_missions.read((origin, mission_id)); assert(!mission.is_zero(), 'no fleet to recall'); self.fleet_return_planet(origin, mission.fleet); self.active_missions.write((origin, mission_id), Zeroable::zero()); - self.active_missions_len.write(origin, self.active_missions_len.read(origin) - 1); + self.remove_hostile_mission(mission.destination, mission_id); } - fn collect_debris(ref self: ContractState, mission_id: u8) { + fn collect_debris(ref self: ContractState, mission_id: usize) { let caller = get_caller_address(); let origin = self.get_owned_planet(caller); let mut mission = self.active_missions.read((origin, mission_id)); @@ -822,7 +821,7 @@ mod NoGame { } fn get_spendable_resources(self: @ContractState, planet_id: u16) -> ERC20s { - let planet_owner = self.erc721.read().owner_of(planet_id.into()); + let planet_owner = self.erc721.read().ng_owner_of(planet_id.into()); let steel = self.steel.read().balance_of(planet_owner).low / E18; let quartz = self.quartz.read().balance_of(planet_owner).low / E18; let tritium = self.tritium.read().balance_of(planet_owner).low / E18; @@ -972,26 +971,42 @@ mod NoGame { } } - fn get_mission_details(self: @ContractState, planet_id: u16, mission_id: u8) -> Mission { + fn get_mission_details(self: @ContractState, planet_id: u16, mission_id: usize) -> Mission { self.active_missions.read((planet_id, mission_id)) } fn get_active_missions(self: @ContractState, planet_id: u16) -> Array { let mut arr: Array = array![]; let len = self.active_missions_len.read(planet_id); - let mut i: u8 = 1; + let mut i = 1; loop { - if i.into() > len { + if i > len { break; } - arr.append(self.active_missions.read((planet_id, i))); + let mission = self.active_missions.read((planet_id, i)); + if !mission.is_zero() { + arr.append(mission); + } i += 1; }; arr } - fn get_hostile_missions(self: @ContractState, planet_id: u16) -> (PlanetPosition, u32) { - self.hostile_missions.read(planet_id) + fn get_hostile_missions(self: @ContractState, planet_id: u16) -> Array { + let mut arr: Array = array![]; + let len = self.hostile_missions_len.read(planet_id); + let mut i = 1; + loop { + if i > len { + break; + } + let mission = self.hostile_missions.read((planet_id, i)); + if !mission.is_zero() { + arr.append(mission); + } + i += 1; + }; + arr } fn get_travel_time( @@ -1443,6 +1458,57 @@ mod NoGame { self.plasma_available.write(planet_id, d.plasma); } + fn add_active_mission(ref self: ContractState, planet_id: u16, mission: Mission) -> usize { + let len = self.active_missions_len.read(planet_id); + let mut i = 1; + loop { + if i > len { + self.active_missions.write((planet_id, i), mission); + self.active_missions_len.write(planet_id, i); + break; + } + i.print(); + let mission = self.active_missions.read((planet_id, i)); + if mission.is_zero() { + self.active_missions.write((planet_id, i), mission); + } + i += 1; + }; + i + } + + fn add_hostile_mission(ref self: ContractState, planet_id: u16, mission: HostileMission) { + let len = self.hostile_missions_len.read(planet_id); + let mut i = 1; + loop { + if i > len { + self.hostile_missions.write((planet_id, i), mission); + self.hostile_missions_len.write(planet_id, i); + break; + } + let mission = self.hostile_missions.read((planet_id, i)); + if mission.is_zero() { + self.hostile_missions.write((planet_id, i), mission); + } + i += 1; + }; + } + + fn remove_hostile_mission(ref self: ContractState, planet_id: u16, id_to_remove: usize) { + let len = self.hostile_missions_len.read(planet_id); + let mut i = 1; + loop { + if i > len { + break; + } + let mission = self.hostile_missions.read((planet_id, i)); + if mission.id_at_origin == id_to_remove { + self.hostile_missions.write((planet_id, i), Zeroable::zero()); + } + i += 1; + } + } + fn position_to_celestia_production(self: @ContractState, orbit: u8) -> u16 { if orbit == 1 { return 48; diff --git a/src/libraries/i128.cairo b/src/libraries/i128.cairo index 0f862de..7c9e4e2 100644 --- a/src/libraries/i128.cairo +++ b/src/libraries/i128.cairo @@ -16,15 +16,15 @@ fn to_signed(a: u128, is_positive: bool) -> i128 { -a_signed } } +// impl I128Serde of Serde { +// fn serialize(self: @i128, ref output: Array) { +// output.append((*self).into()); +// } +// fn deserialize(ref serialized: Span) -> Option { +// let felt_val = *(serialized.pop_front().expect('i128 deserialize')); +// let i128_val = felt_val.try_into().expect('i128 Overflow'); +// Option::Some(i128_val) +// } +// } -impl I128Serde of Serde { - fn serialize(self: @i128, ref output: Array) { - output.append((*self).into()); - } - fn deserialize(ref serialized: Span) -> Option { - let felt_val = *(serialized.pop_front().expect('i128 deserialize')); - let i128_val = felt_val.try_into().expect('i128 Overflow'); - Option::Some(i128_val) - } -} diff --git a/src/libraries/types.cairo b/src/libraries/types.cairo index 95c9d5e..71e40a0 100644 --- a/src/libraries/types.cairo +++ b/src/libraries/types.cairo @@ -307,6 +307,40 @@ impl PrintUnit of PrintTrait { } } +#[derive(Copy, Default, PartialEq, Drop, Serde, starknet::Store)] +struct HostileMission { + origin: u16, + id_at_origin: usize, + time_arrival: u64, + number_of_ships: u32, +} + +impl HostileMissionPrint of PrintTrait { + fn print(self: HostileMission) { + self.origin.print(); + self.id_at_origin.print(); + self.time_arrival.print(); + self.number_of_ships.print(); + } +} + +impl HostileMissionZeroable of Zeroable { + fn zero() -> HostileMission { + HostileMission { + origin: Zeroable::zero(), + id_at_origin: Zeroable::zero(), + time_arrival: Zeroable::zero(), + number_of_ships: Zeroable::zero(), + } + } + fn is_zero(self: HostileMission) -> bool { + self.origin.is_zero() || self.number_of_ships.is_zero() || self.time_arrival.is_zero() + } + fn is_non_zero(self: HostileMission) -> bool { + !self.is_zero() + } +} + #[derive(Copy, Default, PartialEq, Drop, Serde, starknet::Store)] struct Mission { time_start: u64, diff --git a/src/token/erc20.cairo b/src/token/erc20.cairo index 50ab00e..d2963f7 100755 --- a/src/token/erc20.cairo +++ b/src/token/erc20.cairo @@ -26,7 +26,7 @@ mod NGERC20 { use starknet::ContractAddress; use starknet::get_caller_address; - use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; + use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; #[storage] struct Storage { @@ -36,7 +36,7 @@ mod NGERC20 { _balances: LegacyMap, _allowances: LegacyMap<(ContractAddress, ContractAddress), u256>, _minter: ContractAddress, - nft: INGERC721Dispatcher, + nft: IERC721NoGameDispatcher, } #[event] @@ -152,7 +152,7 @@ mod NGERC20 { self._name.write(name_); self._symbol.write(symbol_); self._minter.write(minter_); - self.nft.write(INGERC721Dispatcher { contract_address: nft_address }); + self.nft.write(IERC721NoGameDispatcher { contract_address: nft_address }); } fn _increase_allowance( @@ -208,7 +208,7 @@ mod NGERC20 { assert(!sender.is_zero(), 'ERC20: transfer from 0'); assert(!recipient.is_zero(), 'ERC20: transfer to 0'); assert( - !self.nft.read().balance_of(recipient).is_zero(), 'recipient is not planet owner' + !self.nft.read().ng_balance_of(recipient).is_zero(), 'recipient is not planet owner' ); self._balances.write(sender, self._balances.read(sender) - amount); self._balances.write(recipient, self._balances.read(recipient) + amount); diff --git a/src/token/erc721.cairo b/src/token/erc721.cairo index 18d53eb..a62c84a 100644 --- a/src/token/erc721.cairo +++ b/src/token/erc721.cairo @@ -1,56 +1,47 @@ +// SPDX-License-Identifier: MIT +// OpenZeppelin Contracts for Cairo v0.8.0-beta.0 (token/erc721/erc721.cairo) use starknet::ContractAddress; #[starknet::interface] -trait INGERC721 { - fn name(self: @T) -> felt252; - fn symbol(self: @T) -> felt252; - fn token_uri(self: @T, token_id: u256) -> felt252; - fn balance_of(self: @T, account: ContractAddress) -> u256; - fn owner_of(self: @T, token_id: u256) -> ContractAddress; - fn transfer_from(ref self: T, from: ContractAddress, to: ContractAddress, token_id: u256); - fn safe_transfer_from( - ref self: T, from: ContractAddress, to: ContractAddress, token_id: u256, data: Span - ); - fn approve(ref self: T, to: ContractAddress, token_id: u256); - fn set_approval_for_all(ref self: T, operator: ContractAddress, approved: bool); - fn get_approved(self: @T, token_id: u256) -> ContractAddress; - fn is_approved_for_all(self: @T, owner: ContractAddress, operator: ContractAddress) -> bool; - fn token_of(self: @T, address: ContractAddress) -> u256; - fn base_uri(self: @T) -> felt252; - fn set_minter(ref self: T, address: ContractAddress); - fn set_base_uri(ref self: T, uri: felt252); - fn mint(ref self: T, to: ContractAddress, token_id: u256); +trait IERC721NoGame { + fn ng_balance_of(self: @TState, account: ContractAddress) -> u256; + fn ng_owner_of(self: @TState, token_id: u256) -> ContractAddress; + fn token_of(self: @TState, address: ContractAddress) -> u256; + fn mint(ref self: TState, to: ContractAddress, token_id: u256); } #[starknet::contract] mod NGERC721 { - use array::SpanTrait; use openzeppelin::account; use openzeppelin::introspection::dual_src5::DualCaseSRC5; use openzeppelin::introspection::dual_src5::DualCaseSRC5Trait; - use openzeppelin::introspection::interface::ISRC5; - use openzeppelin::introspection::interface::ISRC5Camel; - use openzeppelin::introspection::src5; + use openzeppelin::introspection::src5::SRC5 as src5_component; use openzeppelin::token::erc721::dual721_receiver::DualCaseERC721Receiver; use openzeppelin::token::erc721::dual721_receiver::DualCaseERC721ReceiverTrait; use openzeppelin::token::erc721::interface; - use option::OptionTrait; use starknet::ContractAddress; use starknet::get_caller_address; - use zeroable::Zeroable; + + component!(path: src5_component, storage: src5, event: SRC5Event); + #[abi(embed_v0)] + impl SRC5Impl = src5_component::SRC5Impl; + #[abi(embed_v0)] + impl SRC5CamelImpl = src5_component::SRC5CamelImpl; + impl SRC5InternalImpl = src5_component::InternalImpl; #[storage] struct Storage { - _name: felt252, - _symbol: felt252, - _owners: LegacyMap, - _tokens: LegacyMap, - _balances: LegacyMap, - _token_approvals: LegacyMap, - _operator_approvals: LegacyMap<(ContractAddress, ContractAddress), bool>, - _token_uri: LegacyMap, - _minter: ContractAddress, - _base_uri: felt252, + ERC721_name: felt252, + ERC721_symbol: felt252, + ERC721_owners: LegacyMap, + ERC721_balances: LegacyMap, + ERC721_token_approvals: LegacyMap, + ERC721_operator_approvals: LegacyMap<(ContractAddress, ContractAddress), bool>, + ERC721_token_uri: LegacyMap, + ERC721_tokens: LegacyMap, + ERC721_minter: ContractAddress, + #[substorage(v0)] + src5: src5_component::Storage } #[event] @@ -58,33 +49,55 @@ mod NGERC721 { enum Event { Transfer: Transfer, Approval: Approval, - ApprovalForAll: ApprovalForAll + ApprovalForAll: ApprovalForAll, + SRC5Event: src5_component::Event } #[derive(Drop, starknet::Event)] struct Transfer { + #[key] from: ContractAddress, + #[key] to: ContractAddress, + #[key] token_id: u256 } #[derive(Drop, starknet::Event)] struct Approval { + #[key] owner: ContractAddress, + #[key] approved: ContractAddress, + #[key] token_id: u256 } #[derive(Drop, starknet::Event)] struct ApprovalForAll { + #[key] owner: ContractAddress, + #[key] operator: ContractAddress, approved: bool } + mod Errors { + const INVALID_TOKEN_ID: felt252 = 'ERC721: invalid token ID'; + const INVALID_ACCOUNT: felt252 = 'ERC721: invalid account'; + const UNAUTHORIZED: felt252 = 'ERC721: unauthorized caller'; + const APPROVAL_TO_OWNER: felt252 = 'ERC721: approval to owner'; + const SELF_APPROVAL: felt252 = 'ERC721: self approval'; + const INVALID_RECEIVER: felt252 = 'ERC721: invalid receiver'; + const ALREADY_MINTED: felt252 = 'ERC721: token already minted'; + const WRONG_SENDER: felt252 = 'ERC721: wrong sender'; + const SAFE_MINT_FAILED: felt252 = 'ERC721: safe mint failed'; + const SAFE_TRANSFER_FAILED: felt252 = 'ERC721: safe transfer failed'; + } + #[constructor] fn constructor( - ref self: ContractState, name: felt252, symbol: felt252, minter: ContractAddress + ref self: ContractState, name: felt252, symbol: felt252, minter: ContractAddress, ) { self.initializer(name, symbol, minter); } @@ -94,31 +107,56 @@ mod NGERC721 { // #[external(v0)] - impl SRC5Impl of ISRC5 { - fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - let unsafe_state = src5::SRC5::unsafe_new_contract_state(); - src5::SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id) - } - } - #[external(v0)] - impl NGERC721Impl of super::INGERC721 { + impl ERC721MetadataImpl of interface::IERC721Metadata { fn name(self: @ContractState) -> felt252 { - self._name.read() + self.ERC721_name.read() } fn symbol(self: @ContractState) -> felt252 { - self._symbol.read() + self.ERC721_symbol.read() } fn token_uri(self: @ContractState, token_id: u256) -> felt252 { - assert(self._exists(token_id), 'ERC721: invalid token ID'); - self._token_uri.read(token_id) + assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); + self.ERC721_token_uri.read(token_id) + } + } + + #[external(v0)] + impl ERC721NoGameImpl of super::IERC721NoGame { + fn ng_balance_of(self: @ContractState, account: ContractAddress) -> u256 { + assert(!account.is_zero(), Errors::INVALID_ACCOUNT); + self.ERC721_balances.read(account) + } + + fn ng_owner_of(self: @ContractState, token_id: u256) -> ContractAddress { + self._owner_of(token_id) + } + + fn token_of(self: @ContractState, address: ContractAddress) -> u256 { + self.ERC721_tokens.read(address) + } + + fn mint(ref self: ContractState, to: ContractAddress, token_id: u256) { + assert(get_caller_address() == self.ERC721_minter.read(), 'ERC721 caller not minter'); + InternalImpl::_mint(ref self, to, token_id); + self.ERC721_tokens.write(to, token_id); } + } + #[external(v0)] + impl ERC721MetadataCamelOnlyImpl of interface::IERC721MetadataCamelOnly { + fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { + assert(self._exists(tokenId), Errors::INVALID_TOKEN_ID); + self.ERC721_token_uri.read(tokenId) + } + } + #[external(v0)] + impl ERC721Impl of interface::IERC721 { fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { - assert(!account.is_zero(), 'ERC721: invalid account'); - self._balances.read(account) + assert(!account.is_zero(), Errors::INVALID_ACCOUNT); + self.ERC721_balances.read(account) } fn owner_of(self: @ContractState, token_id: u256) -> ContractAddress { @@ -126,14 +164,14 @@ mod NGERC721 { } fn get_approved(self: @ContractState, token_id: u256) -> ContractAddress { - assert(self._exists(token_id), 'ERC721: invalid token ID'); - self._token_approvals.read(token_id) + assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); + self.ERC721_token_approvals.read(token_id) } fn is_approved_for_all( self: @ContractState, owner: ContractAddress, operator: ContractAddress ) -> bool { - self._operator_approvals.read((owner, operator)) + self.ERC721_operator_approvals.read((owner, operator)) } fn approve(ref self: ContractState, to: ContractAddress, token_id: u256) { @@ -141,8 +179,8 @@ mod NGERC721 { let caller = get_caller_address(); assert( - owner == caller || NGERC721Impl::is_approved_for_all(@self, owner, caller), - 'ERC721: unauthorized caller' + owner == caller || ERC721Impl::is_approved_for_all(@self, owner, caller), + Errors::UNAUTHORIZED ); self._approve(to, token_id); } @@ -157,8 +195,7 @@ mod NGERC721 { ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u256 ) { assert( - self._is_approved_or_owner(get_caller_address(), token_id), - 'ERC721: unauthorized caller' + self._is_approved_or_owner(get_caller_address(), token_id), Errors::UNAUTHORIZED ); self._transfer(from, to, token_id); } @@ -171,32 +208,50 @@ mod NGERC721 { data: Span ) { assert( - self._is_approved_or_owner(get_caller_address(), token_id), - 'ERC721: unauthorized caller' + self._is_approved_or_owner(get_caller_address(), token_id), Errors::UNAUTHORIZED ); self._safe_transfer(from, to, token_id, data); } + } + #[external(v0)] + impl ERC721CamelOnlyImpl of interface::IERC721CamelOnly { + fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 { + ERC721Impl::balance_of(self, account) + } - fn token_of(self: @ContractState, address: ContractAddress) -> u256 { - self._tokens.read(address) + fn ownerOf(self: @ContractState, tokenId: u256) -> ContractAddress { + ERC721Impl::owner_of(self, tokenId) } - fn base_uri(self: @ContractState) -> felt252 { - self._base_uri.read() + + fn getApproved(self: @ContractState, tokenId: u256) -> ContractAddress { + ERC721Impl::get_approved(self, tokenId) } - fn set_minter(ref self: ContractState, address: ContractAddress) { - self._minter.write(address); + fn isApprovedForAll( + self: @ContractState, owner: ContractAddress, operator: ContractAddress + ) -> bool { + ERC721Impl::is_approved_for_all(self, owner, operator) } - fn set_base_uri(ref self: ContractState, uri: felt252) { - self._base_uri.write(uri); + fn setApprovalForAll(ref self: ContractState, operator: ContractAddress, approved: bool) { + ERC721Impl::set_approval_for_all(ref self, operator, approved) } - fn mint(ref self: ContractState, to: ContractAddress, token_id: u256) { - assert(get_caller_address() == self._minter.read(), 'Caller not minter'); - InternalImpl::_mint(ref self, to, token_id); - self._tokens.write(to, token_id); + fn transferFrom( + ref self: ContractState, from: ContractAddress, to: ContractAddress, tokenId: u256 + ) { + ERC721Impl::transfer_from(ref self, from, to, tokenId) + } + + fn safeTransferFrom( + ref self: ContractState, + from: ContractAddress, + to: ContractAddress, + tokenId: u256, + data: Span + ) { + ERC721Impl::safe_transfer_from(ref self, from, to, tokenId, data) } } @@ -207,46 +262,43 @@ mod NGERC721 { #[generate_trait] impl InternalImpl of InternalTrait { fn initializer( - ref self: ContractState, name_: felt252, symbol_: felt252, minter: ContractAddress + ref self: ContractState, name: felt252, symbol: felt252, minter: ContractAddress ) { - self._name.write(name_); - self._symbol.write(symbol_); - self._minter.write(minter); - - let mut unsafe_state = src5::SRC5::unsafe_new_contract_state(); - src5::SRC5::InternalImpl::register_interface(ref unsafe_state, interface::IERC721_ID); - src5::SRC5::InternalImpl::register_interface( - ref unsafe_state, interface::IERC721_METADATA_ID - ); + self.ERC721_name.write(name); + self.ERC721_symbol.write(symbol); + self.ERC721_minter.write(minter); + + self.src5.register_interface(interface::IERC721_ID); + self.src5.register_interface(interface::IERC721_METADATA_ID); } fn _owner_of(self: @ContractState, token_id: u256) -> ContractAddress { - let owner = self._owners.read(token_id); + let owner = self.ERC721_owners.read(token_id); match owner.is_zero() { bool::False(()) => owner, - bool::True(()) => panic_with_felt252('ERC721: invalid token ID') + bool::True(()) => panic_with_felt252(Errors::INVALID_TOKEN_ID) } } fn _exists(self: @ContractState, token_id: u256) -> bool { - !self._owners.read(token_id).is_zero() + !self.ERC721_owners.read(token_id).is_zero() } fn _is_approved_or_owner( self: @ContractState, spender: ContractAddress, token_id: u256 ) -> bool { let owner = self._owner_of(token_id); - let is_approved_for_all = NGERC721Impl::is_approved_for_all(self, owner, spender); + let is_approved_for_all = ERC721Impl::is_approved_for_all(self, owner, spender); owner == spender || is_approved_for_all - || spender == NGERC721Impl::get_approved(self, token_id) + || spender == ERC721Impl::get_approved(self, token_id) } fn _approve(ref self: ContractState, to: ContractAddress, token_id: u256) { let owner = self._owner_of(token_id); - assert(owner != to, 'ERC721: approval to owner'); + assert(owner != to, Errors::APPROVAL_TO_OWNER); - self._token_approvals.write(token_id, to); + self.ERC721_token_approvals.write(token_id, to); self.emit(Approval { owner, approved: to, token_id }); } @@ -256,17 +308,17 @@ mod NGERC721 { operator: ContractAddress, approved: bool ) { - assert(owner != operator, 'ERC721: self approval'); - self._operator_approvals.write((owner, operator), approved); + assert(owner != operator, Errors::SELF_APPROVAL); + self.ERC721_operator_approvals.write((owner, operator), approved); self.emit(ApprovalForAll { owner, operator, approved }); } fn _mint(ref self: ContractState, to: ContractAddress, token_id: u256) { - assert(!to.is_zero(), 'ERC721: invalid receiver'); - assert(!self._exists(token_id), 'ERC721: token already minted'); - InternalImpl::_assert_balance_is_zero(@self, to); - self._balances.write(to, self._balances.read(to) + 1); - self._owners.write(token_id, to); + assert(!to.is_zero(), Errors::INVALID_RECEIVER); + assert(!self._exists(token_id), Errors::ALREADY_MINTED); + + self.ERC721_balances.write(to, self.ERC721_balances.read(to) + 1); + self.ERC721_owners.write(token_id, to); self.emit(Transfer { from: Zeroable::zero(), to, token_id }); } @@ -274,16 +326,16 @@ mod NGERC721 { fn _transfer( ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u256 ) { - assert(!to.is_zero(), 'ERC721: invalid receiver'); + assert(!to.is_zero(), Errors::INVALID_RECEIVER); let owner = self._owner_of(token_id); - assert(from == owner, 'ERC721: wrong sender'); - InternalImpl::_assert_balance_is_zero(@self, to); + assert(from == owner, Errors::WRONG_SENDER); + // Implicit clear approvals, no need to emit an event - self._token_approvals.write(token_id, Zeroable::zero()); + self.ERC721_token_approvals.write(token_id, Zeroable::zero()); - self._balances.write(from, self._balances.read(from) - 1); - self._balances.write(to, self._balances.read(to) + 1); - self._owners.write(token_id, to); + self.ERC721_balances.write(from, self.ERC721_balances.read(from) - 1); + self.ERC721_balances.write(to, self.ERC721_balances.read(to) + 1); + self.ERC721_owners.write(token_id, to); self.emit(Transfer { from, to, token_id }); } @@ -292,10 +344,10 @@ mod NGERC721 { let owner = self._owner_of(token_id); // Implicit clear approvals, no need to emit an event - self._token_approvals.write(token_id, Zeroable::zero()); + self.ERC721_token_approvals.write(token_id, Zeroable::zero()); - self._balances.write(owner, self._balances.read(owner) - 1); - self._owners.write(token_id, Zeroable::zero()); + self.ERC721_balances.write(owner, self.ERC721_balances.read(owner) - 1); + self.ERC721_owners.write(token_id, Zeroable::zero()); self.emit(Transfer { from: owner, to: Zeroable::zero(), token_id }); } @@ -306,7 +358,7 @@ mod NGERC721 { self._mint(to, token_id); assert( _check_on_erc721_received(Zeroable::zero(), to, token_id, data), - 'ERC721: safe mint failed' + Errors::SAFE_MINT_FAILED ); } @@ -319,21 +371,16 @@ mod NGERC721 { ) { self._transfer(from, to, token_id); assert( - _check_on_erc721_received(from, to, token_id, data), 'ERC721: safe transfer failed' + _check_on_erc721_received(from, to, token_id, data), Errors::SAFE_TRANSFER_FAILED ); } fn _set_token_uri(ref self: ContractState, token_id: u256, token_uri: felt252) { - assert(self._exists(token_id), 'ERC721: invalid token ID'); - self._token_uri.write(token_id, token_uri) - } - - fn _assert_balance_is_zero(self: @ContractState, address: ContractAddress) { - assert(self._balances.read(address) == 0, 'Max token balance reached'); + assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); + self.ERC721_token_uri.write(token_id, token_uri) } } - #[internal] fn _check_on_erc721_received( from: ContractAddress, to: ContractAddress, token_id: u256, data: Span ) -> bool { diff --git a/tests/lib.cairo b/tests/lib.cairo index ad82bc6..4eac352 100644 --- a/tests/lib.cairo +++ b/tests/lib.cairo @@ -6,10 +6,6 @@ mod internal_functions { mod mine_production; } -mod token_tests { - mod erc721; -} - mod view_tests { mod general_view; mod compound_view; diff --git a/tests/token_tests/erc721.cairo b/tests/token_tests/erc721.cairo deleted file mode 100644 index abdbf15..0000000 --- a/tests/token_tests/erc721.cairo +++ /dev/null @@ -1,112 +0,0 @@ -// use array::ArrayTrait; -// use array::SpanTrait; -// use clone::Clone; -// use option::OptionTrait; -// use result::ResultTrait; -// use traits::Into; -// use traits::TryInto; -// use starknet::testing::cheatcode; -// use starknet::info::get_contract_address; -// use starknet::ClassHash; -// use starknet::ContractAddress; -// use starknet::ClassHashIntoFelt252; -// use starknet::ContractAddressIntoFelt252; -// use starknet::Felt252TryIntoClassHash; -// use starknet::Felt252TryIntoContractAddress; - -// use forge_print::PrintTrait; -// use cheatcodes::start_prank; - -// use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait, NGERC721}; -// use nogame::game::main::NoGame; - -// #[test] -// fn erc721_test() { -// let contracts = set_up(); -// let erc721 = INGERC721Dispatcher { contract_address: contracts.erc721 }; - -// erc721.set_minter(contracts.account1); -// start_prank(contracts.erc721, contracts.account1); -// erc721.mint(contracts.account2, 1.into()); -// } - -// const PK1: felt252 = 0x1; -// const PK2: felt252 = 0x2; -// const PK3: felt252 = 0x3; - -// struct Contracts { -// account1: ContractAddress, -// account2: ContractAddress, -// account3: ContractAddress, -// erc721: ContractAddress, -// steel: ContractAddress, -// quartz: ContractAddress, -// tritium: ContractAddress, -// game: ContractAddress, -// } - -// fn set_up() -> Contracts { -// let class_hash = declare('Account'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append(PK1); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _account1 = deploy(prepared).unwrap(); - -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append(PK2); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _account2 = deploy(prepared).unwrap(); - -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append(PK3); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _account3 = deploy(prepared).unwrap(); - -// let class_hash = declare('NGERC721'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append('nogame-planet'); -// call_data.append('NGPL'); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _erc721 = deploy(prepared).unwrap(); - -// let class_hash = declare('NoGame'); -// let prepared = PreparedContract { -// class_hash: class_hash, constructor_calldata: @ArrayTrait::new() -// }; -// let _game = deploy(prepared).unwrap(); - -// let class_hash = declare('NGERC20'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append('Nogame Steel'); -// call_data.append('NGST'); -// call_data.append(_game.into()); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _steel = deploy(prepared).unwrap(); - -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append('Nogame Quartz'); -// call_data.append('NGQZ'); -// call_data.append(_game.into()); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _quartz = deploy(prepared).unwrap(); - -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append('Nogame Tritium'); -// call_data.append('NGTR'); -// call_data.append(_game.into()); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _tritium = deploy(prepared).unwrap(); - -// Contracts { -// account1: _account1, -// account2: _account2, -// account3: _account3, -// erc721: _erc721, -// steel: _steel, -// quartz: _quartz, -// tritium: _tritium, -// game: _game -// } -// } - - diff --git a/tests/utils.cairo b/tests/utils.cairo index fa261ff..749b3c1 100644 --- a/tests/utils.cairo +++ b/tests/utils.cairo @@ -7,7 +7,7 @@ use xoroshiro::xoroshiro::{IXoroshiroDispatcher, IXoroshiroDispatcherTrait, Xoro use nogame::game::interface::{INoGameDispatcher, INoGameDispatcherTrait}; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use snforge_std::{declare, ContractClassTrait, start_warp, start_prank, stop_prank, PrintTrait}; @@ -20,7 +20,7 @@ const YEAR: u64 = 31_557_600; #[derive(Copy, Drop, Serde)] struct Dispatchers { - erc721: INGERC721Dispatcher, + erc721: IERC721NoGameDispatcher, steel: INGERC20Dispatcher, quartz: INGERC20Dispatcher, tritium: INGERC20Dispatcher, @@ -79,7 +79,7 @@ fn set_up() -> Dispatchers { let _eth = contract.deploy(@calldata).expect('failed to deploy eth'); Dispatchers { - erc721: INGERC721Dispatcher { contract_address: _erc721 }, + erc721: IERC721NoGameDispatcher { contract_address: _erc721 }, steel: INGERC20Dispatcher { contract_address: _steel }, quartz: INGERC20Dispatcher { contract_address: _quartz }, tritium: INGERC20Dispatcher { contract_address: _tritium }, diff --git a/tests/view_tests/defence_view.cairo b/tests/view_tests/defence_view.cairo index 2c3f0c8..3ac4f91 100644 --- a/tests/view_tests/defence_view.cairo +++ b/tests/view_tests/defence_view.cairo @@ -10,7 +10,7 @@ use nogame::libraries::types::{ ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, init_game, set_up}; #[test] diff --git a/tests/view_tests/dockyard_view.cairo b/tests/view_tests/dockyard_view.cairo index 81ae395..b48c25b 100644 --- a/tests/view_tests/dockyard_view.cairo +++ b/tests/view_tests/dockyard_view.cairo @@ -10,7 +10,7 @@ use nogame::libraries::types::{ ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, init_game, set_up}; #[test] diff --git a/tests/view_tests/fleet_view.cairo b/tests/view_tests/fleet_view.cairo index 5813b01..3234117 100644 --- a/tests/view_tests/fleet_view.cairo +++ b/tests/view_tests/fleet_view.cairo @@ -7,15 +7,36 @@ use snforge_std::{start_prank, start_warp}; use nogame::game::interface::{INoGameDispatcher, INoGameDispatcherTrait}; use nogame::libraries::types::{ - ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost + ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost, + Fleet }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; -use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, init_game, set_up}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; +use tests::utils::{ + E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, init_game, set_up, build_basic_mines, + advance_game_state +}; -#[tests] -fn test_is_noob_protected() { // TODO - assert(0 == 0, 'todo'); +#[test] +fn test_is_noob_protected() { + let dsp = set_up(); + init_game(dsp); + + start_prank(dsp.game.contract_address, ACCOUNT1()); + dsp.game.generate_planet(); + start_prank(dsp.game.contract_address, ACCOUNT2()); + dsp.game.generate_planet(); + build_basic_mines(dsp.game); + advance_game_state(dsp.game); + start_prank(dsp.game.contract_address, ACCOUNT1()); + build_basic_mines(dsp.game); + + assert(dsp.game.is_noob_protected(1, 2) == true, 'wrong noob true'); + assert(dsp.game.is_noob_protected(2, 1) == true, 'wrong noob true'); + + advance_game_state(dsp.game); + assert(dsp.game.is_noob_protected(2, 1) == false, 'wrong noob false'); + assert(dsp.game.is_noob_protected(2, 1) == false, 'wrong noob false'); } #[test] @@ -25,7 +46,43 @@ fn test_get_mission_details() { // TODO #[test] fn test_get_hostile_missions() { // TODO - assert(0 == 0, 'todo'); + let dsp = set_up(); + init_game(dsp); + + start_prank(dsp.game.contract_address, ACCOUNT1()); + dsp.game.generate_planet(); + start_prank(dsp.game.contract_address, ACCOUNT2()); + dsp.game.generate_planet(); + build_basic_mines(dsp.game); + advance_game_state(dsp.game); + start_prank(dsp.game.contract_address, ACCOUNT1()); + build_basic_mines(dsp.game); + advance_game_state(dsp.game); + dsp.game.digital_systems_upgrade(); + dsp.game.digital_systems_upgrade(); + dsp.game.digital_systems_upgrade(); + dsp.game.digital_systems_upgrade(); + + dsp.game.carrier_build(5); + + let p2_position = dsp.game.get_planet_position(2); + + let mut fleet: Fleet = Default::default(); + fleet.carrier = 1; + + dsp.game.send_fleet(fleet, p2_position, false); + dsp.game.send_fleet(fleet, p2_position, false); + // dsp.game.send_fleet(fleet, p2_position, false); + dsp.game.recall_fleet(1); + dsp.game.send_fleet(fleet, p2_position, false); + let mut missions = dsp.game.get_hostile_missions(2); + loop { + if missions.len().is_zero() { + break; + } + missions.pop_front().unwrap().print(); + '--------------'.print(); + } } #[test] diff --git a/tests/view_tests/research_view.cairo b/tests/view_tests/research_view.cairo index dc5ccad..aaf6aac 100644 --- a/tests/view_tests/research_view.cairo +++ b/tests/view_tests/research_view.cairo @@ -10,7 +10,7 @@ use nogame::libraries::types::{ ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, init_game, set_up}; #[test] diff --git a/tests/write_tests/compound_write.cairo b/tests/write_tests/compound_write.cairo index 6dc7af9..c051912 100644 --- a/tests/write_tests/compound_write.cairo +++ b/tests/write_tests/compound_write.cairo @@ -11,7 +11,7 @@ use nogame::libraries::types::{ ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, DEPLOYER, init_game, set_up}; #[test] diff --git a/tests/write_tests/defence_write.cairo b/tests/write_tests/defence_write.cairo index 739bd01..3cffbdd 100644 --- a/tests/write_tests/defence_write.cairo +++ b/tests/write_tests/defence_write.cairo @@ -11,7 +11,7 @@ use nogame::libraries::types::{ ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, DEPLOYER, init_game, set_up}; #[test] diff --git a/tests/write_tests/dockyard_write.cairo b/tests/write_tests/dockyard_write.cairo index 8cb3a6b..4afe0e6 100644 --- a/tests/write_tests/dockyard_write.cairo +++ b/tests/write_tests/dockyard_write.cairo @@ -11,7 +11,7 @@ use nogame::libraries::types::{ ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, DEPLOYER, init_game, set_up}; #[test] diff --git a/tests/write_tests/general_write.cairo b/tests/write_tests/general_write.cairo index 91bf2e4..a371029 100644 --- a/tests/write_tests/general_write.cairo +++ b/tests/write_tests/general_write.cairo @@ -11,7 +11,7 @@ use nogame::libraries::types::{ ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, DEPLOYER, init_game, set_up}; #[test] @@ -29,7 +29,7 @@ fn test_generate() { dsp.eth.balance_of(DEPLOYER()) == owner_balance_before + planet_price.into(), 'planet1 not paid' ); - assert(dsp.erc721.balance_of(ACCOUNT1()).low == 1, 'wrong nft balance'); + assert(dsp.erc721.ng_balance_of(ACCOUNT1()).low == 1, 'wrong nft balance'); assert(dsp.steel.balance_of(ACCOUNT1()).low == 500 * E18, 'wrong steel balance'); assert(dsp.quartz.balance_of(ACCOUNT1()).low == 300 * E18, 'wrong quartz balance'); assert(dsp.tritium.balance_of(ACCOUNT1()).low == 100 * E18, 'wrong steel balance'); @@ -42,7 +42,7 @@ fn test_generate() { dsp.eth.balance_of(DEPLOYER()) == owner_balance_before + planet_price.into(), 'planet2 not paid' ); - assert(dsp.erc721.balance_of(ACCOUNT2()).low == 1, 'wrong nft balance'); + assert(dsp.erc721.ng_balance_of(ACCOUNT2()).low == 1, 'wrong nft balance'); assert(dsp.steel.balance_of(ACCOUNT2()).low == 500 * E18, 'wrong steel balance'); assert(dsp.quartz.balance_of(ACCOUNT2()).low == 300 * E18, 'wrong quartz balance'); assert(dsp.tritium.balance_of(ACCOUNT2()).low == 100 * E18, 'wrong steel balance'); diff --git a/tests/write_tests/research_write.cairo b/tests/write_tests/research_write.cairo index 7335f39..42b84a3 100644 --- a/tests/write_tests/research_write.cairo +++ b/tests/write_tests/research_write.cairo @@ -11,7 +11,7 @@ use nogame::libraries::types::{ ERC20s, EnergyCost, TechLevels, TechsCost, ShipsLevels, ShipsCost, DefencesLevels, DefencesCost }; use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait}; -use nogame::token::erc721::{INGERC721Dispatcher, INGERC721DispatcherTrait}; +use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait}; use tests::utils::{E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, DEPLOYER, init_game, set_up}; #[test] diff --git a/utils.cairo b/utils.cairo deleted file mode 100644 index 551a68b..0000000 --- a/utils.cairo +++ /dev/null @@ -1,107 +0,0 @@ -// use array::ArrayTrait; -// use array::SpanTrait; -// use clone::Clone; -// use option::OptionTrait; -// use result::ResultTrait; -// use traits::Into; -// use traits::TryInto; -// use starknet::testing::cheatcode; -// use starknet::ClassHash; -// use starknet::ContractAddress; -// use starknet::ClassHashIntoFelt252; -// use starknet::ContractAddressIntoFelt252; -// use starknet::Felt252TryIntoClassHash; -// use starknet::Felt252TryIntoContractAddress; - -// use openzeppelin::account::account::Account; -// use openzeppelin::token::erc20::erc20::ERC20; - -// use nogame::token::erc721::NGERC721; -// use nogame::game::main::NoGame; - -// const PK1: felt252 = 0x1; -// const PK2: felt252 = 0x2; -// const PK3: felt252 = 0x3; - -// struct Contracts { -// account1: ContractAddress, -// account2: ContractAddress, -// account3: ContractAddress, -// erc721: ContractAddress, -// steel: ContractAddress, -// quartz: ContractAddress, -// tritium: ContractAddress, -// game: ContractAddress, -// } - -// fn set_up() -> Contracts { -// let class_hash = declare('Account'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append(PK1); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _account1 = deploy(prepared).unwrap(); - -// let class_hash = declare('Account'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append(PK2); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _account2 = deploy(prepared).unwrap(); - -// let class_hash = declare('Account'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append(PK3); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _account3 = deploy(prepared).unwrap(); - -// let class_hash = declare('NGERC721'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append('nogame-planet'); -// call_data.append('NGPL'); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _erc721 = deploy(prepared).unwrap(); - -// let class_hash = declare('ERC20'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append('Nogame Steel'); -// call_data.append('NGST'); -// call_data.append(0.into()); -// call_data.append(0.into()); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _steel = deploy(prepared).unwrap(); - -// let class_hash = declare('ERC20'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append('Nogame Quartz'); -// call_data.append('NGQZ'); -// call_data.append(0.into()); -// call_data.append(0.into()); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _quartz = deploy(prepared).unwrap(); - -// let class_hash = declare('ERC20'); -// let mut call_data: Array = ArrayTrait::new(); -// call_data.append('Nogame Tritium'); -// call_data.append('NGTR'); -// call_data.append(0.into()); -// call_data.append(0.into()); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _tritium = deploy(prepared).unwrap(); - -// let class_hash = declare('NoGame'); -// let mut call_data: Array = ArrayTrait::new(); -// let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @call_data }; -// let _game = deploy(prepared).unwrap(); - -// Contracts { -// account1: _account1, -// account2: _account2, -// account3: _account3, -// erc721: _erc721, -// steel: _steel, -// quartz: _quartz, -// tritium: _tritium, -// game: _game -// } -// } - -