forked from dojoengine/origami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
317 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,94 @@ | ||
mod setup { | ||
// Core imports | ||
|
||
use core::debug::PrintTrait; | ||
|
||
// Starknet imports | ||
|
||
use starknet::ContractAddress; | ||
use starknet::testing::{set_contract_address}; | ||
|
||
// Dojo imports | ||
|
||
use dojo::world::{IWorldDispatcherTrait, IWorldDispatcher}; | ||
use dojo::test_utils::{spawn_test_world, deploy_contract}; | ||
|
||
// Internal imports | ||
|
||
use matchmaker::models::player::Player; | ||
use matchmaker::models::league::League; | ||
use matchmaker::models::registry::Registry; | ||
use matchmaker::models::slot::Slot; | ||
use matchmaker::systems::maker::{maker, IMakerDispatcher, IMakerDispatcherTrait}; | ||
|
||
// Constants | ||
|
||
fn PLAYER() -> ContractAddress { | ||
starknet::contract_address_const::<'PLAYER'>() | ||
} | ||
|
||
fn ANYONE() -> ContractAddress { | ||
starknet::contract_address_const::<'ANYONE'>() | ||
} | ||
|
||
fn SOMEONE() -> ContractAddress { | ||
starknet::contract_address_const::<'SOMEONE'>() | ||
} | ||
|
||
fn NOONE() -> ContractAddress { | ||
starknet::contract_address_const::<'NOONE'>() | ||
} | ||
|
||
const REGISTRY_ID: u32 = 0; | ||
|
||
#[derive(Drop)] | ||
struct Systems { | ||
maker: IMakerDispatcher, | ||
} | ||
|
||
#[derive(Drop)] | ||
struct Context { | ||
registry_id: u32, | ||
player_id: ContractAddress, | ||
someone_id: ContractAddress, | ||
anyone_id: ContractAddress, | ||
noone_id: ContractAddress, | ||
} | ||
|
||
#[inline(always)] | ||
fn spawn() -> (IWorldDispatcher, Systems, Context) { | ||
// [Setup] World | ||
let mut models = core::array::ArrayTrait::new(); | ||
models.append(matchmaker::models::player::player::TEST_CLASS_HASH); | ||
models.append(matchmaker::models::league::league::TEST_CLASS_HASH); | ||
models.append(matchmaker::models::registry::registry::TEST_CLASS_HASH); | ||
models.append(matchmaker::models::slot::slot::TEST_CLASS_HASH); | ||
let world = spawn_test_world(models); | ||
|
||
// [Setup] Systems | ||
let maker_address = deploy_contract(maker::TEST_CLASS_HASH, array![].span()); | ||
let systems = Systems { maker: IMakerDispatcher { contract_address: maker_address }, }; | ||
|
||
// [Setup] Context | ||
set_contract_address(SOMEONE()); | ||
systems.maker.create(world); | ||
systems.maker.subscribe(world); | ||
set_contract_address(ANYONE()); | ||
systems.maker.create(world); | ||
systems.maker.subscribe(world); | ||
set_contract_address(NOONE()); | ||
systems.maker.create(world); | ||
systems.maker.subscribe(world); | ||
set_contract_address(PLAYER()); | ||
let context = Context { | ||
registry_id: REGISTRY_ID, | ||
player_id: PLAYER(), | ||
someone_id: SOMEONE(), | ||
anyone_id: ANYONE(), | ||
noone_id: NOONE() | ||
}; | ||
|
||
// [Return] | ||
(world, systems, context) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Core imports | ||
|
||
use core::debug::PrintTrait; | ||
|
||
// Starknet imports | ||
|
||
use starknet::testing::set_contract_address; | ||
|
||
// Dojo imports | ||
|
||
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; | ||
|
||
// Internal imports | ||
|
||
use matchmaker::store::{Store, StoreTrait}; | ||
use matchmaker::models::player::{Player, PlayerTrait, PlayerAssert}; | ||
use matchmaker::models::registry::{Registry, RegistryTrait, RegistryAssert}; | ||
use matchmaker::models::league::{League, LeagueTrait, LeagueAssert}; | ||
use matchmaker::models::slot::{Slot, SlotTrait}; | ||
use matchmaker::systems::maker::IMakerDispatcherTrait; | ||
use matchmaker::tests::setup::{setup, setup::Systems}; | ||
|
||
#[test] | ||
fn test_maker_create() { | ||
// [Setup] | ||
let (world, systems, context) = setup::spawn(); | ||
let store = StoreTrait::new(world); | ||
|
||
// [Create] | ||
systems.maker.create(world); | ||
|
||
// [Assert] Player | ||
let player = store.player(context.registry_id, context.player_id); | ||
assert(player.id == context.player_id, 'Create: wrong player id'); | ||
assert(player.league_id == 0, 'Create: wrong league id'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Core imports | ||
|
||
use core::debug::PrintTrait; | ||
|
||
// Starknet imports | ||
|
||
use starknet::testing::set_contract_address; | ||
|
||
// Dojo imports | ||
|
||
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; | ||
|
||
// Internal imports | ||
|
||
use matchmaker::store::{Store, StoreTrait}; | ||
use matchmaker::models::player::{Player, PlayerTrait, PlayerAssert}; | ||
use matchmaker::models::registry::{Registry, RegistryTrait, RegistryAssert}; | ||
use matchmaker::models::league::{League, LeagueTrait, LeagueAssert}; | ||
use matchmaker::models::slot::{Slot, SlotTrait}; | ||
use matchmaker::systems::maker::IMakerDispatcherTrait; | ||
use matchmaker::tests::setup::{setup, setup::Systems}; | ||
|
||
#[test] | ||
fn test_maker_fight() { | ||
// [Setup] | ||
let (world, systems, context) = setup::spawn(); | ||
let store = StoreTrait::new(world); | ||
|
||
// [Create] | ||
systems.maker.create(world); | ||
|
||
// [Subscribe] | ||
systems.maker.subscribe(world); | ||
|
||
// [Fight] | ||
let player = store.player(context.registry_id, context.player_id); | ||
let rating = player.rating; | ||
systems.maker.fight(world); | ||
|
||
// [Assert] Player | ||
let player = store.player(context.registry_id, context.player_id); | ||
assert(player.rating != rating, 'Fight: wrong player rating'); | ||
} |
Oops, something went wrong.