diff --git a/packages/slot/src/lib.cairo b/packages/slot/src/lib.cairo index 7cd602d..1c77e3e 100644 --- a/packages/slot/src/lib.cairo +++ b/packages/slot/src/lib.cairo @@ -14,6 +14,8 @@ mod types { mod models { mod index; + mod account; + mod team; mod deployment; mod service; } diff --git a/packages/slot/src/models/account.cairo b/packages/slot/src/models/account.cairo new file mode 100644 index 0000000..ce3ed6b --- /dev/null +++ b/packages/slot/src/models/account.cairo @@ -0,0 +1,92 @@ +// Intenral imports + +use arcade_slot::models::index::Account; + +// Errors + +pub mod errors { + pub const ACCOUNT_ALREADY_EXISTS: felt252 = 'Account: already exists'; + pub const ACCOUNT_NOT_EXIST: felt252 = 'Account: does not exist'; + pub const ACCOUNT_INVALID_IDENTIFIER: felt252 = 'Account: invalid identifier'; + pub const ACCOUNT_INVALID_USERNAME: felt252 = 'Account: invalid username'; +} + +#[generate_trait] +impl AccountImpl of AccountTrait { + #[inline] + fn new( + id: felt252, controllers: u32, name: felt252, username: felt252, socials: ByteArray, + ) -> Account { + // [Check] Inputs + AccountAssert::assert_valid_identifier(id); + AccountAssert::assert_valid_username(username); + // [Return] Account + Account { + id: id, + controllers: controllers, + name: name, + username: username, + socials: socials, + credits: 0, + } + } +} + +#[generate_trait] +impl AccountAssert of AssertTrait { + #[inline] + fn assert_does_not_exist(self: Account) { + assert(self.name == 0, errors::ACCOUNT_ALREADY_EXISTS); + } + + #[inline] + fn assert_does_exist(self: Account) { + assert(self.name != 0, errors::ACCOUNT_NOT_EXIST); + } + + #[inline] + fn assert_valid_identifier(identifier: felt252) { + assert(identifier != 0, errors::ACCOUNT_INVALID_IDENTIFIER); + } + + #[inline] + fn assert_valid_username(username: felt252) { + assert(username != 0, errors::ACCOUNT_INVALID_USERNAME); + } +} + +#[cfg(test)] +mod tests { + // Local imports + + use super::{Account, AccountTrait, AccountAssert}; + + // Constants + + const IDENTIFIER: felt252 = 'ID'; + const USERNAME: felt252 = 'USERNAME'; + + #[test] + fn test_deployment_new() { + let account = AccountTrait::new(IDENTIFIER, 0, 'NAME', USERNAME, "{}"); + assert_eq!(account.id, IDENTIFIER); + assert_eq!(account.controllers, 0); + assert_eq!(account.name, 'NAME'); + assert_eq!(account.username, USERNAME); + assert_eq!(account.socials, "{}"); + assert_eq!(account.credits, 0); + } + + #[test] + fn test_deployment_assert_does_exist() { + let account = AccountTrait::new(IDENTIFIER, 0, 'NAME', USERNAME, "{}"); + account.assert_does_exist(); + } + + #[test] + #[should_panic(expected: 'Account: already exists')] + fn test_deployment_revert_already_exists() { + let account = AccountTrait::new(IDENTIFIER, 0, 'NAME', USERNAME, "{}"); + account.assert_does_not_exist(); + } +} diff --git a/packages/slot/src/models/index.cairo b/packages/slot/src/models/index.cairo index 2693ae6..5c3bc0b 100644 --- a/packages/slot/src/models/index.cairo +++ b/packages/slot/src/models/index.cairo @@ -81,3 +81,16 @@ pub struct Service { version: felt252, default_version: felt252, } + +#[derive(Clone, Drop, Serde)] +#[dojo::model] +pub struct Game { + #[key] + id: felt252, + name: felt252, + description: ByteArray, + priority: u8, + socials: ByteArray, + metadata: ByteArray, + active: bool, +} diff --git a/packages/slot/src/models/team.cairo b/packages/slot/src/models/team.cairo new file mode 100644 index 0000000..4142383 --- /dev/null +++ b/packages/slot/src/models/team.cairo @@ -0,0 +1,80 @@ +// Intenral imports + +use arcade_slot::models::index::Team; + +// Errors + +pub mod errors { + pub const TEAM_ALREADY_EXISTS: felt252 = 'Team: already exists'; + pub const TEAM_NOT_EXIST: felt252 = 'Team: does not exist'; + pub const TEAM_INVALID_IDENTIFIER: felt252 = 'Team: invalid identifier'; + pub const TEAM_INVALID_NAME: felt252 = 'Team: invalid name'; +} + +#[generate_trait] +impl TeamImpl of TeamTrait { + #[inline] + fn new(id: felt252, name: felt252, description: ByteArray) -> Team { + // [Check] Inputs + TeamAssert::assert_valid_identifier(id); + TeamAssert::assert_valid_name(name); + // [Return] Team + Team { id: id, name: name, description: description, } + } +} + +#[generate_trait] +impl TeamAssert of AssertTrait { + #[inline] + fn assert_does_not_exist(self: Team) { + assert(self.name == 0, errors::TEAM_ALREADY_EXISTS); + } + + #[inline] + fn assert_does_exist(self: Team) { + assert(self.name != 0, errors::TEAM_NOT_EXIST); + } + + #[inline] + fn assert_valid_identifier(identifier: felt252) { + assert(identifier != 0, errors::TEAM_INVALID_IDENTIFIER); + } + + #[inline] + fn assert_valid_name(name: felt252) { + assert(name != 0, errors::TEAM_INVALID_NAME); + } +} + +#[cfg(test)] +mod tests { + // Local imports + + use super::{Team, TeamTrait, TeamAssert}; + + // Constants + + const IDENTIFIER: felt252 = 'ID'; + const NAME: felt252 = 'NAME'; + + #[test] + fn test_deployment_new() { + let team = TeamTrait::new(IDENTIFIER, 'NAME', ""); + assert_eq!(team.id, IDENTIFIER); + assert_eq!(team.name, 'NAME'); + assert_eq!(team.description, ""); + } + + #[test] + fn test_deployment_assert_does_exist() { + let team = TeamTrait::new(IDENTIFIER, 'NAME', ""); + team.assert_does_exist(); + } + + #[test] + #[should_panic(expected: 'Team: already exists')] + fn test_deployment_revert_already_exists() { + let account = TeamTrait::new(IDENTIFIER, 0, 'NAME', USERNAME, ""); + account.assert_does_not_exist(); + } +}