-
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.
✨ Create missing models and according basic impls
- Loading branch information
Showing
6 changed files
with
494 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Intenral imports | ||
|
||
use arcade_slot::models::index::Controller; | ||
|
||
// Errors | ||
|
||
pub mod errors { | ||
pub const CONTROLLER_ALREADY_EXISTS: felt252 = 'Controller: already exists'; | ||
pub const CONTROLLER_NOT_EXIST: felt252 = 'Controller: does not exist'; | ||
pub const CONTROLLER_INVALID_ACCOUNT_ID: felt252 = 'Controller: invalid account id'; | ||
pub const CONTROLLER_INVALID_IDENTIFIER: felt252 = 'Controller: invalid identifier'; | ||
pub const CONTROLLER_INVALID_SIGNERS: felt252 = 'Controller: invalid signers'; | ||
pub const CONTROLLER_INVALID_ADDRESS: felt252 = 'Controller: invalid address'; | ||
pub const CONTROLLER_INVALID_NETWORK: felt252 = 'Controller: invalid network'; | ||
} | ||
|
||
#[generate_trait] | ||
impl ControllerImpl of ControllerTrait { | ||
#[inline] | ||
fn new( | ||
account_id: felt252, | ||
id: felt252, | ||
signers: u32, | ||
address: felt252, | ||
network: felt252, | ||
constructor_calldata: ByteArray, | ||
) -> Controller { | ||
// [Check] Inputs | ||
ControllerAssert::assert_valid_account_id(account_id); | ||
ControllerAssert::assert_valid_identifier(id); | ||
ControllerAssert::assert_valid_signers(signers); | ||
ControllerAssert::assert_valid_address(address); | ||
ControllerAssert::assert_valid_network(network); | ||
// [Return] Controller | ||
Controller { | ||
account_id: account_id, | ||
id: id, | ||
signers: signers, | ||
address: address, | ||
network: network, | ||
constructor_calldata: constructor_calldata | ||
} | ||
} | ||
} | ||
|
||
#[generate_trait] | ||
impl ControllerAssert of AssertTrait { | ||
#[inline] | ||
fn assert_does_not_exist(self: Controller) { | ||
assert(self.account_id == 0, errors::CONTROLLER_ALREADY_EXISTS); | ||
} | ||
|
||
#[inline] | ||
fn assert_does_exist(self: Controller) { | ||
assert(self.account_id != 0, errors::CONTROLLER_NOT_EXIST); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_identifier(id: felt252) { | ||
assert(id != 0, errors::CONTROLLER_INVALID_IDENTIFIER); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_account_id(account_id: felt252) { | ||
assert(account_id != 0, errors::CONTROLLER_INVALID_ACCOUNT_ID); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_signers(signers: u32) { | ||
assert(signers != 0, errors::CONTROLLER_INVALID_SIGNERS); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_address(address: felt252) { | ||
assert(address != 0, errors::CONTROLLER_INVALID_ADDRESS); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_network(network: felt252) { | ||
assert(network != 0, errors::CONTROLLER_INVALID_NETWORK); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
// Local imports | ||
|
||
use super::{Controller, ControllerTrait, ControllerAssert}; | ||
|
||
// Constants | ||
|
||
const IDENTIFIER: felt252 = 'IDENTIFIER'; | ||
const ACCOUNT_ID: felt252 = 'ACCOUNT_ID'; | ||
const SIGNERS: u32 = 1; | ||
const ADDRESS: felt252 = 'ADDRESS'; | ||
const NETWORK: felt252 = 'NETWORK'; | ||
|
||
#[test] | ||
fn test_deployment_new() { | ||
let controller = ControllerTrait::new( | ||
ACCOUNT_ID, IDENTIFIER, SIGNERS, ADDRESS, NETWORK, "" | ||
); | ||
assert_eq!(controller.id, IDENTIFIER); | ||
assert_eq!(controller.account_id, ACCOUNT_ID); | ||
assert_eq!(controller.signers, SIGNERS); | ||
assert_eq!(controller.address, ADDRESS); | ||
assert_eq!(controller.network, NETWORK); | ||
assert_eq!(controller.constructor_calldata, ""); | ||
} | ||
|
||
#[test] | ||
fn test_deployment_assert_does_exist() { | ||
let controller = ControllerTrait::new( | ||
ACCOUNT_ID, IDENTIFIER, SIGNERS, ADDRESS, NETWORK, "" | ||
); | ||
controller.assert_does_exist(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Controller: already exists')] | ||
fn test_deployment_revert_already_exists() { | ||
let controller = ControllerTrait::new( | ||
ACCOUNT_ID, IDENTIFIER, SIGNERS, ADDRESS, NETWORK, "" | ||
); | ||
controller.assert_does_not_exist(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Controller: invalid account id')] | ||
fn test_deployment_revert_invalid_account_id() { | ||
ControllerTrait::new(0, IDENTIFIER, SIGNERS, ADDRESS, NETWORK, ""); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Controller: invalid identifier')] | ||
fn test_deployment_revert_invalid_identifier() { | ||
ControllerTrait::new(ACCOUNT_ID, 0, SIGNERS, ADDRESS, NETWORK, ""); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Controller: invalid signers')] | ||
fn test_deployment_revert_invalid_signers() { | ||
ControllerTrait::new(ACCOUNT_ID, IDENTIFIER, 0, ADDRESS, NETWORK, ""); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Controller: invalid address')] | ||
fn test_deployment_revert_invalid_address() { | ||
ControllerTrait::new(ACCOUNT_ID, IDENTIFIER, SIGNERS, 0, NETWORK, ""); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Controller: invalid network')] | ||
fn test_deployment_revert_invalid_network() { | ||
ControllerTrait::new(ACCOUNT_ID, IDENTIFIER, SIGNERS, ADDRESS, 0, ""); | ||
} | ||
} |
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,100 @@ | ||
// Intenral imports | ||
|
||
use arcade_slot::models::index::Game; | ||
|
||
// Errors | ||
|
||
pub mod errors { | ||
pub const GAME_ALREADY_EXISTS: felt252 = 'Game: already exists'; | ||
pub const GAME_NOT_EXIST: felt252 = 'Game: does not exist'; | ||
pub const GAME_INVALID_IDENTIFIER: felt252 = 'Game: invalid identifier'; | ||
pub const GAME_INVALID_NAME: felt252 = 'Game: invalid name'; | ||
pub const GAME_INVALID_PRIORITY: felt252 = 'Game: invalid priority'; | ||
} | ||
|
||
#[generate_trait] | ||
impl GameImpl of GameTrait { | ||
#[inline] | ||
fn new( | ||
id: felt252, name: felt252, description: ByteArray, socials: ByteArray, metadata: ByteArray, | ||
) -> Game { | ||
// [Check] Inputs | ||
GameAssert::assert_valid_identifier(id); | ||
GameAssert::assert_valid_name(name); | ||
// [Return] Game | ||
Game { | ||
id: id, | ||
name: name, | ||
description: description, | ||
priority: 0, | ||
socials: socials, | ||
metadata: metadata, | ||
active: true, | ||
} | ||
} | ||
} | ||
|
||
#[generate_trait] | ||
impl GameAssert of AssertTrait { | ||
#[inline] | ||
fn assert_does_not_exist(self: Game) { | ||
assert(self.name == 0, errors::GAME_ALREADY_EXISTS); | ||
} | ||
|
||
#[inline] | ||
fn assert_does_exist(self: Game) { | ||
assert(self.name != 0, errors::GAME_NOT_EXIST); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_identifier(identifier: felt252) { | ||
assert(identifier != 0, errors::GAME_INVALID_IDENTIFIER); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_name(name: felt252) { | ||
assert(name != 0, errors::GAME_INVALID_NAME); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
// Local imports | ||
|
||
use super::{Game, GameTrait, GameAssert}; | ||
|
||
// Constants | ||
|
||
const IDENTIFIER: felt252 = 'ID'; | ||
const NAME: felt252 = 'NAME'; | ||
|
||
#[test] | ||
fn test_service_new() { | ||
let service = GameTrait::new(IDENTIFIER, NAME, "", "", ""); | ||
assert_eq!(service.id, IDENTIFIER); | ||
assert_eq!(service.name, NAME); | ||
assert_eq!(service.description, ""); | ||
assert_eq!(service.socials, ""); | ||
assert_eq!(service.metadata, ""); | ||
assert_eq!(service.active, true); | ||
} | ||
|
||
#[test] | ||
fn test_service_assert_does_exist() { | ||
let service = GameTrait::new(IDENTIFIER, NAME, "", "", ""); | ||
service.assert_does_exist(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Game: already exists')] | ||
fn test_service_revert_already_exists() { | ||
let service = GameTrait::new(IDENTIFIER, NAME, "", "", ""); | ||
service.assert_does_not_exist(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Game: invalid name')] | ||
fn test_service_revert_invalid_name() { | ||
GameTrait::new(IDENTIFIER, 0, "", "", ""); | ||
} | ||
} |
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,94 @@ | ||
// Intenral imports | ||
|
||
use arcade_slot::models::index::Member; | ||
use arcade_slot::types::role::Role; | ||
// Errors | ||
|
||
pub mod errors { | ||
pub const MEMBER_ALREADY_EXISTS: felt252 = 'Member: already exists'; | ||
pub const MEMBER_NOT_EXIST: felt252 = 'Member: does not exist'; | ||
pub const MEMBER_INVALID_ACCOUNT_ID: felt252 = 'Member: invalid account id'; | ||
pub const MEMBER_INVALID_TEAM_ID: felt252 = 'Member: invalid team id'; | ||
pub const MEMBER_INVALID_ROLE: felt252 = 'Member: invalid role'; | ||
} | ||
|
||
#[generate_trait] | ||
impl MemberImpl of MemberTrait { | ||
#[inline] | ||
fn new(account_id: felt252, team_id: felt252, role: Role) -> Member { | ||
// [Check] Inputs | ||
MemberAssert::assert_valid_account_id(account_id); | ||
MemberAssert::assert_valid_team_id(team_id); | ||
MemberAssert::assert_valid_role(role); | ||
// [Return] Member | ||
Member { account_id: account_id, team_id: team_id, role: role.into() } | ||
} | ||
} | ||
|
||
#[generate_trait] | ||
impl MemberAssert of AssertTrait { | ||
#[inline] | ||
fn assert_does_not_exist(self: Member) { | ||
assert(self.role == Role::None.into(), errors::MEMBER_ALREADY_EXISTS); | ||
} | ||
|
||
#[inline] | ||
fn assert_does_exist(self: Member) { | ||
assert(self.role != Role::None.into(), errors::MEMBER_NOT_EXIST); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_account_id(account_id: felt252) { | ||
assert(account_id != 0, errors::MEMBER_INVALID_ACCOUNT_ID); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_team_id(team_id: felt252) { | ||
assert(team_id != 0, errors::MEMBER_INVALID_TEAM_ID); | ||
} | ||
|
||
#[inline] | ||
fn assert_valid_role(role: Role) { | ||
assert(role != Role::None, errors::MEMBER_INVALID_ROLE); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
// Local imports | ||
|
||
use super::{Member, MemberTrait, MemberAssert, Role}; | ||
|
||
// Constants | ||
|
||
const ACCOUNT_ID: felt252 = 'ACCOUNT_ID'; | ||
const TEAM_ID: felt252 = 'TEAM_ID'; | ||
const ROLE: Role = Role::Admin; | ||
|
||
#[test] | ||
fn test_deployment_new() { | ||
let member = MemberTrait::new(ACCOUNT_ID, TEAM_ID, ROLE); | ||
assert_eq!(member.account_id, ACCOUNT_ID); | ||
assert_eq!(member.team_id, TEAM_ID); | ||
assert_eq!(member.role, ROLE.into()); | ||
} | ||
|
||
#[test] | ||
fn test_deployment_assert_does_exist() { | ||
let member = MemberTrait::new(ACCOUNT_ID, TEAM_ID, ROLE); | ||
member.assert_does_exist(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Member: already exists')] | ||
fn test_deployment_revert_already_exists() { | ||
let member = MemberTrait::new(ACCOUNT_ID, TEAM_ID, ROLE); | ||
member.assert_does_not_exist(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Member: invalid role')] | ||
fn test_deployment_revert_invalid_role() { | ||
MemberTrait::new(ACCOUNT_ID, TEAM_ID, Role::None); | ||
} | ||
} |
Oops, something went wrong.