-
Notifications
You must be signed in to change notification settings - Fork 2
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
4 changed files
with
187 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ mod types { | |
|
||
mod models { | ||
mod index; | ||
mod account; | ||
mod team; | ||
mod deployment; | ||
mod service; | ||
} |
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,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(); | ||
} | ||
} |
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 |
---|---|---|
@@ -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(); | ||
} | ||
} |