Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
thiscaspar committed Oct 21, 2024
1 parent b347c33 commit 56c429e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Build generated
target/
manifests/
overlays/

# IDE
.idea/
manifests/

# Dirs for debugging
pixelaw/
storage/
5 changes: 3 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-alpha.17#e6bab2d0066
name = "myapp"
version = "0.0.0"
dependencies = [
"dojo",
"pixelaw",
]

[[package]]
name = "pixelaw"
version = "0.3.50"
source = "git+https://github.com/pixelaw/core?tag=v0.4.4#bc5b90840337ccb3303223f24acdccad6ea50886"
version = "0.4.4"
source = "git+https://github.com/pixelaw/core?tag=v0.4.5#cf8fb1b426c8580216dddd649ad1da8a9f0e6dcd"
dependencies = [
"dojo",
]
12 changes: 11 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ version = "0.0.0"
sierra-replace-ids = true

[dependencies]
pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.4.4" }
pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.4.5" }
# pixelaw = { path = "../core/contracts" }


dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.17" }

[[target.dojo]]
build-external-contracts = [
"pixelaw::apps::snake::app::snake",
"pixelaw::apps::snake::app::snake_segment",
"pixelaw::core::models::area::area",
"pixelaw::core::models::area::Area",
"pixelaw::core::models::pixel::pixel",
"pixelaw::core::models::pixel::Pixel",
"pixelaw::core::models::pixel::PixelUpdate",
Expand All @@ -30,6 +36,10 @@ build-external-contracts = [
"pixelaw::core::actions::IActionsDispatcherTrait"
]

[tool.fmt]
sort-module-level-items = true


[scripts]
ready_for_deployment = "bash ./scripts/ready_for_deployment.sh"
initialize = "bash ./scripts/default_auth.sh"
Expand Down
4 changes: 2 additions & 2 deletions dojo_dev.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[world]
description = "Empty PixeLAW world"
name = "myapp"
seed = "dojo_examples"
seed = "pixelaw"

[namespace]
default = "pixelaw"
mappings = { }
mappings = {}

[env]
rpc_url = "http://localhost:5050/"
Expand Down
12 changes: 7 additions & 5 deletions src/app.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ pub mod myapp_actions {
IActionsDispatcherTrait as ICoreActionsDispatcherTrait
};

use pixelaw::core::models::permissions::{Permission};
use pixelaw::core::models::pixel::{Pixel, PixelUpdate};
use pixelaw::core::utils::{get_core_actions, Direction, Position, DefaultParameters};
use pixelaw::core::utils::{
get_callers, get_core_actions, Direction, Position, DefaultParameters
};
use starknet::{
get_tx_info, get_caller_address, get_contract_address, get_execution_info,
contract_address_const, ContractAddress
Expand All @@ -47,8 +48,7 @@ pub mod myapp_actions {
// Load important variables
let core_actions = get_core_actions(world);
let position = default_params.position;
let player = core_actions.get_player_address(default_params.for_player);
let system = core_actions.get_system_address(default_params.for_system);
let (player, system) = get_callers(world, default_params);

// Load the Pixel
let mut pixel = get!(world, (position.x, position.y), (Pixel));
Expand Down Expand Up @@ -78,7 +78,9 @@ pub mod myapp_actions {
app: Option::Some(system),
owner: Option::Some(player),
action: Option::None // Not using this feature for myapp
}
},
default_params.area_hint, // area_hint
false // hook_can_modify
);
}
}
Expand Down
55 changes: 17 additions & 38 deletions src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,51 @@ mod tests {

use myapp::app::{myapp_actions, IMyAppActionsDispatcher, IMyAppActionsDispatcherTrait};
use pixelaw::core::actions::{actions, IActionsDispatcher, IActionsDispatcherTrait};
use pixelaw::core::models::permissions::{permissions};

use pixelaw::core::models::pixel::{Pixel, PixelUpdate};
use pixelaw::core::models::pixel::{pixel};
use pixelaw::core::models::registry::{app, app_name, core_actions_address};
use pixelaw::core::tests::helpers::{
setup_core, setup_core_initialized, setup_apps, setup_apps_initialized, ZERO_ADDRESS,
set_caller, drop_all_events, TEST_POSITION, WHITE_COLOR, RED_COLOR
};
use pixelaw::core::utils::{
get_core_actions, encode_color, decode_color, Direction, Position, DefaultParameters
get_core_actions, encode_rgba, decode_rgba, Direction, Position, DefaultParameters
};
use starknet::class_hash::Felt252TryIntoClassHash;

use zeroable::Zeroable;

// Helper function: deploys world and actions
fn deploy_world() -> (IWorldDispatcher, IActionsDispatcher, IMyAppActionsDispatcher) {
let mut models = array![
pixel::TEST_CLASS_HASH,
app::TEST_CLASS_HASH,
app_name::TEST_CLASS_HASH,
core_actions_address::TEST_CLASS_HASH,
permissions::TEST_CLASS_HASH,
];
let world = spawn_test_world(["pixelaw"].span(), models.span());

// Deploy Core actions
let core_actions_address = world
.deploy_contract('salt1', actions::TEST_CLASS_HASH.try_into().unwrap());
let core_actions = IActionsDispatcher { contract_address: core_actions_address };

fn deploy_app(world: IWorldDispatcher) -> IMyAppActionsDispatcher {
// Deploy MyApp actions
let myapp_actions_address = world
.deploy_contract('salt2', myapp_actions::TEST_CLASS_HASH.try_into().unwrap());
let myapp_actions = IMyAppActionsDispatcher { contract_address: myapp_actions_address };

// Setup dojo auth
world.grant_writer(selector_from_tag!("pixelaw-Pixel"), core_actions_address);
world.grant_writer(selector_from_tag!("pixelaw-App"), core_actions_address);
world.grant_writer(selector_from_tag!("pixelaw-AppName"), core_actions_address);
world.grant_writer(selector_from_tag!("pixelaw-Permissions"), core_actions_address);
world.grant_writer(selector_from_tag!("pixelaw-CoreActionsAddress"), core_actions_address);

// PLEASE ADD YOUR APP PERMISSIONS HERE

(world, core_actions, myapp_actions)
IMyAppActionsDispatcher { contract_address: myapp_actions_address }
}

#[test]
#[available_gas(3000000000)]
fn test_myapp_actions() {
// Deploy everything
let (world, core_actions, myapp_actions) = deploy_world();
let (world, _core_actions, player_1, _player_2) = setup_core_initialized();

core_actions.init();
myapp_actions.init();
// Deploy MyApp actions
let myapp_actions = deploy_app(world);

let player1 = starknet::contract_address_const::<0x1337>();
starknet::testing::set_account_contract_address(player1);
myapp_actions.init();

let color = encode_color(1, 1, 1, 1);
set_caller(player_1);
let color = encode_rgba(1, 1, 1, 1);

myapp_actions
.interact(
DefaultParameters {
for_player: Zeroable::zero(),
for_system: Zeroable::zero(),
player_override: Option::None,
system_override: Option::None,
position: Position { x: 1, y: 1 },
color: color
color: color,
area_hint: Option::None
},
);

Expand Down

0 comments on commit 56c429e

Please sign in to comment.