From 8617e2f4d2cbd189c05d2a0a2dfebb32ce9c2445 Mon Sep 17 00:00:00 2001 From: bal7hazar Date: Thu, 31 Oct 2024 19:45:49 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Upgrade=20done?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/achievement/src/events/index.cairo | 4 +- packages/achievement/src/tests/setup.cairo | 42 +- .../src/tests/test_achievable.cairo | 80 ++-- .../src/tests/test_controllable.cairo | 108 ++--- .../src/tests/test_registrable.cairo | 424 +++++++++--------- 5 files changed, 339 insertions(+), 319 deletions(-) diff --git a/packages/achievement/src/events/index.cairo b/packages/achievement/src/events/index.cairo index a87e6ef..8f1cce5 100644 --- a/packages/achievement/src/events/index.cairo +++ b/packages/achievement/src/events/index.cairo @@ -4,7 +4,7 @@ use achievement::types::task::Task; -#[derive(Clone, Drop, Serde, Introspect, starknet::Event)] +#[derive(Clone, Drop, Serde, Introspect)] #[dojo::event] pub struct Trophy { #[key] @@ -20,7 +20,7 @@ pub struct Trophy { data: ByteArray, } -#[derive(Copy, Drop, Serde, Introspect, starknet::Event)] +#[derive(Copy, Drop, Serde, Introspect)] #[dojo::event] pub struct Progress { #[key] diff --git a/packages/achievement/src/tests/setup.cairo b/packages/achievement/src/tests/setup.cairo index 8bf413c..6ab9466 100644 --- a/packages/achievement/src/tests/setup.cairo +++ b/packages/achievement/src/tests/setup.cairo @@ -63,15 +63,15 @@ mod setup { TestResource::Event(events::e_Trophy::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Event(events::e_Progress::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Contract( - ContractDefTrait::new(Achiever::TEST_CLASS_HASH, "achiever") + ContractDefTrait::new(Achiever::TEST_CLASS_HASH, "Achiever") .with_writer_of([dojo::utils::bytearray_hash(@"namespace")].span()) ), TestResource::Contract( - ContractDefTrait::new(Controller::TEST_CLASS_HASH, "controller") + ContractDefTrait::new(Controller::TEST_CLASS_HASH, "Controller") .with_writer_of([dojo::utils::bytearray_hash(@"namespace")].span()) ), TestResource::Contract( - ContractDefTrait::new(Registrer::TEST_CLASS_HASH, "registrer") + ContractDefTrait::new(Registrer::TEST_CLASS_HASH, "Registrer") .with_writer_of([dojo::utils::bytearray_hash(@"namespace")].span()) ), ].span() @@ -79,25 +79,25 @@ mod setup { } #[inline] - fn spawn_game() { // -> (WorldStorage, Systems, Context) { + fn spawn_game() -> (WorldStorage, Systems, Context) { // [Setup] World - // set_contract_address(OWNER()); + set_contract_address(OWNER()); let namespace_def = setup_namespace(); - let _world = spawn_test_world([namespace_def].span()); - // // [Setup] Systems - // let (achiever_address, _) = world.dns(@"achiever").unwrap(); - // let (controller_address, _) = world.dns(@"controller").unwrap(); - // let (registrer_address, _) = world.dns(@"registrer").unwrap(); - // let systems = Systems { - // achiever: IAchieverDispatcher { contract_address: achiever_address }, - // controller: IControllerDispatcher { contract_address: controller_address }, - // registrer: IRegistrerDispatcher { contract_address: registrer_address }, - // }; - - // // [Setup] Context - // let context = Context { player_id: PLAYER().into() }; - - // // [Return] - // (world, systems, context) + let world = spawn_test_world([namespace_def].span()); + // [Setup] Systems + let (achiever_address, _) = world.dns(@"Achiever").unwrap(); + let (controller_address, _) = world.dns(@"Controller").unwrap(); + let (registrer_address, _) = world.dns(@"Registrer").unwrap(); + let systems = Systems { + achiever: IAchieverDispatcher { contract_address: achiever_address }, + controller: IControllerDispatcher { contract_address: controller_address }, + registrer: IRegistrerDispatcher { contract_address: registrer_address }, + }; + + // [Setup] Context + let context = Context { player_id: PLAYER().into() }; + + // [Return] + (world, systems, context) } } diff --git a/packages/achievement/src/tests/test_achievable.cairo b/packages/achievement/src/tests/test_achievable.cairo index cc5a228..8549cef 100644 --- a/packages/achievement/src/tests/test_achievable.cairo +++ b/packages/achievement/src/tests/test_achievable.cairo @@ -8,6 +8,10 @@ use starknet::ContractAddress; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; use starknet::testing; +// Dojo imports + +use dojo::world::world::Event; + // Internal imports use achievement::types::task::{Task, TaskTrait}; @@ -33,35 +37,51 @@ const TITLE: felt252 = 'Title'; #[test] fn test_achievable_create() { spawn_game(); - // let (_world, _systems, _context) = spawn_game(); -// clear_events(world.dispatcher.contract_address); -// let tasks = array![TaskTrait::new(TASK_ID, TOTAL, "Description")].span(); -// systems -// .achiever -// .create(TROPHY_ID, HIDDEN, INDEX, POINTS, GROUP, ICON, TITLE, "Description", tasks, ""); -// let event = starknet::testing::pop_log::(world.dispatcher.contract_address).unwrap(); -// // FIXME: Cannot check keys because they are shifted due to dojo macros -// assert_eq!(event.hidden, HIDDEN); -// assert_eq!(event.index, INDEX); -// assert_eq!(event.points, POINTS); -// assert_eq!(event.group, GROUP); -// assert_eq!(event.title, TITLE); -// assert_eq!(event.description, "Description"); -// assert_eq!(event.icon, ICON); -// assert_eq!(event.tasks.len(), 1); -// assert_eq!(event.tasks[0].id, @TASK_ID); -// assert_eq!(event.tasks[0].total, @TOTAL); -// assert_eq!(event.tasks[0].description, @"Description"); + let (world, systems, _context) = spawn_game(); + clear_events(world.dispatcher.contract_address); + let tasks = array![TaskTrait::new(TASK_ID, TOTAL, "Description")].span(); + systems + .achiever + .create(TROPHY_ID, HIDDEN, INDEX, POINTS, GROUP, ICON, TITLE, "Description", tasks, ""); + let contract_event = starknet::testing::pop_log::(world.dispatcher.contract_address) + .unwrap(); + match contract_event { + Event::EventEmitted(event) => { + assert_eq!(*event.keys.at(0), TROPHY_ID); + assert_eq!(*event.values.at(0), 0); + assert_eq!(*event.values.at(1), INDEX.into()); + assert_eq!(*event.values.at(2), POINTS.into()); + assert_eq!(*event.values.at(3), GROUP.into()); + assert_eq!(*event.values.at(4), ICON.into()); + assert_eq!(*event.values.at(5), TITLE.into()); + assert_eq!(*event.values.at(6), 0); + assert_eq!(*event.values.at(7), 'Description'); + assert_eq!(*event.values.at(8), 11); + assert_eq!(*event.values.at(9), 1); + assert_eq!(*event.values.at(10), TASK_ID); + assert_eq!(*event.values.at(11), TOTAL.into()); + assert_eq!(*event.values.at(12), 0); + assert_eq!(*event.values.at(13), 'Description'); + assert_eq!(*event.values.at(14), 11); + }, + _ => {}, + } +} +#[test] +fn test_achievable_update() { + let (world, systems, context) = spawn_game(); + clear_events(world.dispatcher.contract_address); + systems.achiever.update(context.player_id, TASK_ID, COUNT); + let contract_event = starknet::testing::pop_log::(world.dispatcher.contract_address) + .unwrap(); + match contract_event { + Event::EventEmitted(event) => { + assert_eq!(*event.keys.at(0), context.player_id); + assert_eq!(*event.keys.at(1), TASK_ID); + assert_eq!(*event.values.at(0), COUNT.into()); + assert_eq!(*event.values.at(1), 0); + }, + _ => {}, + } } -// #[test] -// fn test_achievable_update() { -// let (world, systems, context) = spawn_game(); -// clear_events(world.dispatcher.contract_address); -// systems.achiever.update(context.player_id, TASK_ID, COUNT); -// let event = -// starknet::testing::pop_log::(world.dispatcher.contract_address).unwrap(); -// // FIXME: Cannot check keys because they are shifted due to dojo macros -// assert_eq!(event.count, COUNT); -// assert_eq!(event.time, 0); -// } diff --git a/packages/achievement/src/tests/test_controllable.cairo b/packages/achievement/src/tests/test_controllable.cairo index 3eedb32..aafae96 100644 --- a/packages/achievement/src/tests/test_controllable.cairo +++ b/packages/achievement/src/tests/test_controllable.cairo @@ -1,54 +1,54 @@ -// // Core imports - -// use core::num::traits::Zero; - -// // Starknet imports - -// use starknet::ContractAddress; -// use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; -// use starknet::testing; - -// // Internal imports - -// use achievement::store::{Store, StoreTrait}; -// use achievement::models::game::{Game, GameTrait}; -// use achievement::models::achievement::{Achievement, AchievementTrait}; -// use achievement::tests::mocks::controller::{ -// Controller, IControllerDispatcher, IControllerDispatcherTrait -// }; -// use achievement::tests::setup::setup::{spawn_game, Systems, Context, OWNER, PLAYER}; - -// // Constants - -// const WORLD_ADDRESS: felt252 = 'WORLD'; -// const NAMEPSACE: felt252 = 'NAMESPACE'; - -// // Tests - -// #[test] -// fn test_controllable_assert_is_owner() { -// // [Setup] -// let (world, systems, _context) = spawn_game(); -// let mut store = StoreTrait::new(world); -// let game = GameTrait::new( -// WORLD_ADDRESS, NAMEPSACE, "NAME", "DESCRIPTION", "TORII_URL", "IMAGE_URI", OWNER().into() -// ); -// store.set_game(game); -// // [Assert] -// systems.controller.assert_is_owner(WORLD_ADDRESS, NAMEPSACE); -// } - -// #[test] -// #[should_panic(expected: ('Controllable: unauthorized call', 'ENTRYPOINT_FAILED'))] -// fn test_controllable_assert_is_owner_revert() { -// // [Setup] -// let (world, systems, _context) = spawn_game(); -// let mut store = StoreTrait::new(world); -// let game = GameTrait::new( -// WORLD_ADDRESS, NAMEPSACE, "NAME", "DESCRIPTION", "TORII_URL", "IMAGE_URI", OWNER().into() -// ); -// store.set_game(game); -// // [Assert] -// testing::set_contract_address(PLAYER()); -// systems.controller.assert_is_owner(WORLD_ADDRESS, NAMEPSACE); -// } +// Core imports + +use core::num::traits::Zero; + +// Starknet imports + +use starknet::ContractAddress; +use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; +use starknet::testing; + +// Internal imports + +use achievement::store::{Store, StoreTrait}; +use achievement::models::game::{Game, GameTrait}; +use achievement::models::achievement::{Achievement, AchievementTrait}; +use achievement::tests::mocks::controller::{ + Controller, IControllerDispatcher, IControllerDispatcherTrait +}; +use achievement::tests::setup::setup::{spawn_game, Systems, Context, OWNER, PLAYER}; + +// Constants + +const WORLD_ADDRESS: felt252 = 'WORLD'; +const NAMEPSACE: felt252 = 'NAMESPACE'; + +// Tests + +#[test] +fn test_controllable_assert_is_owner() { + // [Setup] + let (world, systems, _context) = spawn_game(); + let mut store = StoreTrait::new(world); + let game = GameTrait::new( + WORLD_ADDRESS, NAMEPSACE, "NAME", "DESCRIPTION", "TORII_URL", "IMAGE_URI", OWNER().into() + ); + store.set_game(game); + // [Assert] + systems.controller.assert_is_owner(WORLD_ADDRESS, NAMEPSACE); +} + +#[test] +#[should_panic(expected: ('Controllable: unauthorized call', 'ENTRYPOINT_FAILED'))] +fn test_controllable_assert_is_owner_revert() { + // [Setup] + let (world, systems, _context) = spawn_game(); + let mut store = StoreTrait::new(world); + let game = GameTrait::new( + WORLD_ADDRESS, NAMEPSACE, "NAME", "DESCRIPTION", "TORII_URL", "IMAGE_URI", OWNER().into() + ); + store.set_game(game); + // [Assert] + testing::set_contract_address(PLAYER()); + systems.controller.assert_is_owner(WORLD_ADDRESS, NAMEPSACE); +} diff --git a/packages/achievement/src/tests/test_registrable.cairo b/packages/achievement/src/tests/test_registrable.cairo index 8e072af..f6aa526 100644 --- a/packages/achievement/src/tests/test_registrable.cairo +++ b/packages/achievement/src/tests/test_registrable.cairo @@ -1,212 +1,212 @@ -// // Core imports - -// use core::num::traits::Zero; - -// // Starknet imports - -// use starknet::ContractAddress; -// use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; -// use starknet::testing; - -// // Internal imports - -// use achievement::store::{Store, StoreTrait}; -// use achievement::models::game::{Game, GameTrait}; -// use achievement::models::achievement::{Achievement, AchievementTrait}; -// use achievement::tests::mocks::registrer::{ -// Registrer, IRegistrerDispatcher, IRegistrerDispatcherTrait -// }; -// use achievement::tests::setup::setup::{spawn_game, Systems, Context, PLAYER}; - -// // Constants - -// const WORLD_ADDRESS: felt252 = 'WORLD'; -// const NAMEPSACE: felt252 = 'NAMESPACE'; - -// // Helpers - -// fn register_game(systems: @Systems, context: @Context) { -// let name: ByteArray = "NAME"; -// let description: ByteArray = "DESCRIPTION"; -// let torii_url: ByteArray = "TORII_URL"; -// let image_uri: ByteArray = "IMAGE_URI"; -// let owner: felt252 = *context.player_id; -// (*systems) -// .registrer -// .register_game( -// WORLD_ADDRESS, -// NAMEPSACE, -// name.clone(), -// description.clone(), -// torii_url.clone(), -// image_uri.clone(), -// owner -// ); -// } - -// // Tests - -// #[test] -// fn test_registrable_register_game() { -// // [Setup] -// let (world, systems, context) = spawn_game(); -// let name: ByteArray = "NAME"; -// let description: ByteArray = "DESCRIPTION"; -// let torii_url: ByteArray = "TORII_URL"; -// let image_uri: ByteArray = "IMAGE_URI"; -// let owner: felt252 = context.player_id; -// // [Register] Game -// systems -// .registrer -// .register_game( -// WORLD_ADDRESS, -// NAMEPSACE, -// name.clone(), -// description.clone(), -// torii_url.clone(), -// image_uri.clone(), -// owner -// ); -// // [Assert] Game -// let store = StoreTrait::new(world); -// let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); -// assert_eq!(game.world_address, WORLD_ADDRESS); -// assert_eq!(game.namespace, NAMEPSACE); -// assert_eq!(game.published, false); -// assert_eq!(game.whitelisted, false); -// assert_eq!(game.total_karma, 0); -// assert_eq!(game.name, name); -// assert_eq!(game.description, description); -// assert_eq!(game.torii_url, torii_url); -// assert_eq!(game.image_uri, image_uri); -// assert_eq!(game.owner, owner); -// } - -// #[test] -// fn test_registrable_update_game() { -// // [Setup] -// let (world, systems, context) = spawn_game(); -// register_game(@systems, @context); -// // [Update] Game -// let new_name: ByteArray = "NEW_NAME"; -// let new_description: ByteArray = "NEW_DESCRIPTION"; -// let new_torii_url: ByteArray = "NEW_TORII_URL"; -// let new_image_uri: ByteArray = "NEW_IMAGE_URI"; -// systems -// .registrer -// .update_game( -// WORLD_ADDRESS, -// NAMEPSACE, -// new_name.clone(), -// new_description.clone(), -// new_torii_url.clone(), -// new_image_uri.clone() -// ); -// // [Assert] Game -// let store = StoreTrait::new(world); -// let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); -// assert_eq!(game.name, new_name); -// assert_eq!(game.description, new_description); -// assert_eq!(game.torii_url, new_torii_url); -// assert_eq!(game.image_uri, new_image_uri); -// } - -// #[test] -// fn test_registrable_publish_game() { -// // [Setup] -// let (world, systems, context) = spawn_game(); -// register_game(@systems, @context); -// systems.registrer.publish_game(WORLD_ADDRESS, NAMEPSACE); -// // [Assert] Game -// let store = StoreTrait::new(world); -// let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); -// assert_eq!(game.published, true); -// } - -// #[test] -// fn test_registrable_whitelist_game() { -// // [Setup] -// let (world, systems, context) = spawn_game(); -// register_game(@systems, @context); -// systems.registrer.publish_game(WORLD_ADDRESS, NAMEPSACE); -// systems.registrer.whitelist_game(WORLD_ADDRESS, NAMEPSACE); -// // [Assert] Game -// let store = StoreTrait::new(world); -// let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); -// assert_eq!(game.whitelisted, true); -// } - -// #[test] -// fn test_registrable_register_achievement() { -// // [Setup] -// let (world, systems, context) = spawn_game(); -// register_game(@systems, @context); -// // [Register] Achievement -// let identifier: felt252 = 'IDENTIFIER'; -// let karma: u16 = 10; -// systems.registrer.register_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, karma); -// // [Assert] Achievement -// let store = StoreTrait::new(world); -// let achievement = store.get_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); -// assert_eq!(achievement.id, identifier); -// assert_eq!(achievement.karma, karma); -// // [Assert] Game -// let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); -// assert_eq!(game.total_karma, karma); -// } - -// #[test] -// fn test_registrable_update_achievement() { -// // [Setup] -// let (world, systems, context) = spawn_game(); -// register_game(@systems, @context); -// // [Register] Achievement -// let identifier: felt252 = 'IDENTIFIER'; -// let karma: u16 = 10; -// systems.registrer.register_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, karma); -// // [Update] Achievement -// let new_karma: u16 = 20; -// systems.registrer.update_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, new_karma); -// // [Assert] Achievement -// let store = StoreTrait::new(world); -// let achievement = store.get_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); -// assert_eq!(achievement.karma, new_karma); -// // [Assert] Game -// let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); -// assert_eq!(game.total_karma, new_karma); -// } - -// #[test] -// fn test_registrable_publish_achievement() { -// // [Setup] -// let (world, systems, context) = spawn_game(); -// register_game(@systems, @context); -// // [Register] Achievement -// let identifier: felt252 = 'IDENTIFIER'; -// let karma: u16 = 10; -// systems.registrer.register_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, karma); -// // [Publish] Achievement -// systems.registrer.publish_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); -// // [Assert] Achievement -// let store = StoreTrait::new(world); -// let achievement = store.get_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); -// assert_eq!(achievement.published, true); -// } - -// #[test] -// fn test_registrable_whitelist_achievement() { -// // [Setup] -// let (world, systems, context) = spawn_game(); -// register_game(@systems, @context); -// // [Register] Achievement -// let identifier: felt252 = 'IDENTIFIER'; -// let karma: u16 = 10; -// systems.registrer.register_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, karma); -// // [Whitelist] Achievement -// systems.registrer.publish_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); -// systems.registrer.whitelist_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); -// // [Assert] Achievement -// let store = StoreTrait::new(world); -// let achievement = store.get_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); -// assert_eq!(achievement.whitelisted, true); -// } +// Core imports + +use core::num::traits::Zero; + +// Starknet imports + +use starknet::ContractAddress; +use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; +use starknet::testing; + +// Internal imports + +use achievement::store::{Store, StoreTrait}; +use achievement::models::game::{Game, GameTrait}; +use achievement::models::achievement::{Achievement, AchievementTrait}; +use achievement::tests::mocks::registrer::{ + Registrer, IRegistrerDispatcher, IRegistrerDispatcherTrait +}; +use achievement::tests::setup::setup::{spawn_game, Systems, Context, PLAYER}; + +// Constants + +const WORLD_ADDRESS: felt252 = 'WORLD'; +const NAMEPSACE: felt252 = 'NAMESPACE'; + +// Helpers + +fn register_game(systems: @Systems, context: @Context) { + let name: ByteArray = "NAME"; + let description: ByteArray = "DESCRIPTION"; + let torii_url: ByteArray = "TORII_URL"; + let image_uri: ByteArray = "IMAGE_URI"; + let owner: felt252 = *context.player_id; + (*systems) + .registrer + .register_game( + WORLD_ADDRESS, + NAMEPSACE, + name.clone(), + description.clone(), + torii_url.clone(), + image_uri.clone(), + owner + ); +} + +// Tests + +#[test] +fn test_registrable_register_game() { + // [Setup] + let (world, systems, context) = spawn_game(); + let name: ByteArray = "NAME"; + let description: ByteArray = "DESCRIPTION"; + let torii_url: ByteArray = "TORII_URL"; + let image_uri: ByteArray = "IMAGE_URI"; + let owner: felt252 = context.player_id; + // [Register] Game + systems + .registrer + .register_game( + WORLD_ADDRESS, + NAMEPSACE, + name.clone(), + description.clone(), + torii_url.clone(), + image_uri.clone(), + owner + ); + // [Assert] Game + let store = StoreTrait::new(world); + let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); + assert_eq!(game.world_address, WORLD_ADDRESS); + assert_eq!(game.namespace, NAMEPSACE); + assert_eq!(game.published, false); + assert_eq!(game.whitelisted, false); + assert_eq!(game.total_karma, 0); + assert_eq!(game.name, name); + assert_eq!(game.description, description); + assert_eq!(game.torii_url, torii_url); + assert_eq!(game.image_uri, image_uri); + assert_eq!(game.owner, owner); +} + +#[test] +fn test_registrable_update_game() { + // [Setup] + let (world, systems, context) = spawn_game(); + register_game(@systems, @context); + // [Update] Game + let new_name: ByteArray = "NEW_NAME"; + let new_description: ByteArray = "NEW_DESCRIPTION"; + let new_torii_url: ByteArray = "NEW_TORII_URL"; + let new_image_uri: ByteArray = "NEW_IMAGE_URI"; + systems + .registrer + .update_game( + WORLD_ADDRESS, + NAMEPSACE, + new_name.clone(), + new_description.clone(), + new_torii_url.clone(), + new_image_uri.clone() + ); + // [Assert] Game + let store = StoreTrait::new(world); + let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); + assert_eq!(game.name, new_name); + assert_eq!(game.description, new_description); + assert_eq!(game.torii_url, new_torii_url); + assert_eq!(game.image_uri, new_image_uri); +} + +#[test] +fn test_registrable_publish_game() { + // [Setup] + let (world, systems, context) = spawn_game(); + register_game(@systems, @context); + systems.registrer.publish_game(WORLD_ADDRESS, NAMEPSACE); + // [Assert] Game + let store = StoreTrait::new(world); + let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); + assert_eq!(game.published, true); +} + +#[test] +fn test_registrable_whitelist_game() { + // [Setup] + let (world, systems, context) = spawn_game(); + register_game(@systems, @context); + systems.registrer.publish_game(WORLD_ADDRESS, NAMEPSACE); + systems.registrer.whitelist_game(WORLD_ADDRESS, NAMEPSACE); + // [Assert] Game + let store = StoreTrait::new(world); + let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); + assert_eq!(game.whitelisted, true); +} + +#[test] +fn test_registrable_register_achievement() { + // [Setup] + let (world, systems, context) = spawn_game(); + register_game(@systems, @context); + // [Register] Achievement + let identifier: felt252 = 'IDENTIFIER'; + let karma: u16 = 10; + systems.registrer.register_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, karma); + // [Assert] Achievement + let store = StoreTrait::new(world); + let achievement = store.get_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); + assert_eq!(achievement.id, identifier); + assert_eq!(achievement.karma, karma); + // [Assert] Game + let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); + assert_eq!(game.total_karma, karma); +} + +#[test] +fn test_registrable_update_achievement() { + // [Setup] + let (world, systems, context) = spawn_game(); + register_game(@systems, @context); + // [Register] Achievement + let identifier: felt252 = 'IDENTIFIER'; + let karma: u16 = 10; + systems.registrer.register_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, karma); + // [Update] Achievement + let new_karma: u16 = 20; + systems.registrer.update_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, new_karma); + // [Assert] Achievement + let store = StoreTrait::new(world); + let achievement = store.get_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); + assert_eq!(achievement.karma, new_karma); + // [Assert] Game + let game = store.get_game(WORLD_ADDRESS, NAMEPSACE); + assert_eq!(game.total_karma, new_karma); +} + +#[test] +fn test_registrable_publish_achievement() { + // [Setup] + let (world, systems, context) = spawn_game(); + register_game(@systems, @context); + // [Register] Achievement + let identifier: felt252 = 'IDENTIFIER'; + let karma: u16 = 10; + systems.registrer.register_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, karma); + // [Publish] Achievement + systems.registrer.publish_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); + // [Assert] Achievement + let store = StoreTrait::new(world); + let achievement = store.get_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); + assert_eq!(achievement.published, true); +} + +#[test] +fn test_registrable_whitelist_achievement() { + // [Setup] + let (world, systems, context) = spawn_game(); + register_game(@systems, @context); + // [Register] Achievement + let identifier: felt252 = 'IDENTIFIER'; + let karma: u16 = 10; + systems.registrer.register_achievement(WORLD_ADDRESS, NAMEPSACE, identifier, karma); + // [Whitelist] Achievement + systems.registrer.publish_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); + systems.registrer.whitelist_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); + // [Assert] Achievement + let store = StoreTrait::new(world); + let achievement = store.get_achievement(WORLD_ADDRESS, NAMEPSACE, identifier); + assert_eq!(achievement.whitelisted, true); +}