Skip to content

Commit

Permalink
bump pixelaw to 0.5.4 and fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
thiscaspar committed Nov 15, 2024
1 parent 6af154a commit 4de322d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "My Project",
"image": "ghcr.io/pixelaw/core:0.5.3",
"image": "ghcr.io/pixelaw/core:0.5.4",
"forwardPorts": [
5050,
8080,
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Build generated
target/
manifests/
overlays/
manifest_dev.json

# IDE
.idea/
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Follow the asdf installation instructions.

```
asdf plugin add dojo https://github.com/dojoengine/asdf-dojo
asdf install dojo 1.0.0-alpha.11
asdf install dojo 1.0.0
```

## Install scarb
Expand All @@ -48,7 +48,7 @@ And after moving into contracts directory, the versions for these libs are set i

```bash
# Run Katana
katana --disable-fee --allowed-origins "*"
katana --dev --dev.no-fee --http.cors_origins "*"
```

#### Terminal two
Expand All @@ -58,13 +58,13 @@ katana --disable-fee --allowed-origins "*"
sozo build

# Migrate the example
sozo migrate apply
sozo migrate

# Initialize the pixelaw app
scarb run init_auth

# Start Torii
torii --world 0x263ae44e5414519a5c5a135cccaf3d9d7ee196d37e8de47a178da91f3de9b34 --allowed-origins "*"
torii --world 0x6f130c8e150882e39cbe878c650c8f35c86579180dbc77d0c1cbe169449b5f6 --http.cors_origins "*"
```

### How to deploy
Expand Down
12 changes: 10 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_cairo_test"
version = "1.0.0-rc.0"
source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0#74280d48fa2828095331487dede59f9b2e378cd3"
dependencies = [
"dojo",
]

[[package]]
name = "dojo_plugin"
version = "2.8.4"
Expand All @@ -19,13 +27,13 @@ name = "myapp"
version = "0.0.0"
dependencies = [
"dojo",
"dojo_cairo_test",
"pixelaw",
]

[[package]]
name = "pixelaw"
version = "0.5.2"
source = "git+https://github.com/pixelaw/core?tag=v0.5.2#22eec50675dd440a1bf183283a6d16effff866bf"
version = "0.5.4"
dependencies = [
"dojo",
]
41 changes: 20 additions & 21 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,34 @@ version = "0.0.0"
sierra-replace-ids = true

[dependencies]
pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.5.3" }
# pixelaw = { path = "../core/contracts" }
#pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.5.4" }
pixelaw = { path = "../core/contracts" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0" }

[dev-dependencies]
dojo_cairo_test = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0" }

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

[[target.starknet-contract]]
sierra = true
build-external-contracts = [
"dojo::world::world_contract::world",
"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",
"pixelaw::core::models::queue::queue_item",
"pixelaw::core::models::registry::app",
"pixelaw::core::models::registry::app_name",
"pixelaw::core::models::registry::app_user",
"pixelaw::core::models::registry::core_actions_address",
"pixelaw::core::utils::get_core_actions",
"pixelaw::core::utils::Direction",
"pixelaw::core::utils::Position",
"pixelaw::core::utils::DefaultParameters",
# "pixelaw::core::models::area::Area",
# "pixelaw::core::models::pixel::Pixel",
# "pixelaw::core::models::pixel::PixelUpdate",
# "pixelaw::core::models::queue::QueueItem",
# "pixelaw::core::models::registry::App",
# "pixelaw::core::models::registry::AppName",
# "pixelaw::core::models::registry::CoreActionsAddress",
# "pixelaw::core::utils::get_core_actions",
# "pixelaw::core::utils::Direction",
# "pixelaw::core::utils::Position",
# "pixelaw::core::utils::DefaultParameters",
"pixelaw::core::actions::actions",
"pixelaw::core::actions::IActionsDispatcher",
"pixelaw::core::actions::IActionsDispatcherTrait"
"pixelaw::apps::paint::app::paint_actions",
"pixelaw::apps::snake::app::snake_actions",
# "pixelaw::core::actions::IActionsDispatcher",
# "pixelaw::core::actions::IActionsDispatcherTrait"
]

[tool.fmt]
Expand Down
4 changes: 2 additions & 2 deletions dojo_dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ mappings = {}

[env]
rpc_url = "http://localhost:5050/"
account_address = "0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486"
private_key = "0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a"
account_address = "0x127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec"
private_key = "0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912"
world_address = "0x6f130c8e150882e39cbe878c650c8f35c86579180dbc77d0c1cbe169449b5f6"
26 changes: 22 additions & 4 deletions src/app.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@

use pixelaw::core::utils::{DefaultParameters};
use starknet::ContractAddress;


#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct Player {
#[key]
pub id: u64,
pub score: u64
}

#[derive(Copy, Drop, Serde)]
#[dojo::event]
pub struct Highscore {
#[key]
player_id: u64,
score: u64
}


#[starknet::interface]
Expand All @@ -11,8 +28,8 @@ pub trait IMyAppActions<T> {
/// contracts must be named as such (APP_KEY + underscore + "actions")
#[dojo::contract]
pub mod myapp_actions {
use dojo::model::{ModelStorage};
use debug::PrintTrait;
use dojo::model::{ModelStorage};
use myapp::constants::{APP_KEY, APP_ICON};
use pixelaw::core::actions::{
IActionsDispatcher as ICoreActionsDispatcher,
Expand All @@ -27,9 +44,10 @@ pub mod myapp_actions {
get_tx_info, get_caller_address, get_contract_address, get_execution_info,
contract_address_const, ContractAddress
};

use super::IMyAppActions;

use super::{Player};

// impl: implement functions specified in trait
#[abi(embed_v0)]
impl ActionsImpl of IMyAppActions<ContractState> {
Expand All @@ -54,7 +72,7 @@ pub mod myapp_actions {
let (player, system) = get_callers(ref world, default_params);

// Load the Pixel

let mut pixel: Pixel = world.read_model((position.x, position.y));

// TODO: Load MyApp App Settings like the fade steptime
Expand Down
2 changes: 2 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod app;
pub mod constants;

#[cfg(test)]
mod tests;
57 changes: 39 additions & 18 deletions src/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,43 +1,64 @@
#[cfg(test)]
mod tests {
use debug::PrintTrait;
use dojo::utils::test::{spawn_test_world};

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};

use myapp::app::{myapp_actions, IMyAppActionsDispatcher, IMyAppActionsDispatcherTrait};
use dojo::model::{ModelStorage};
use dojo::world::{
world, IWorldDispatcher, IWorldDispatcherTrait, WorldStorageTrait, WorldStorage
};
use dojo_cairo_test::{
spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, ContractDef,
WorldStorageTestTrait
};
use myapp::app::{
myapp_actions, IMyAppActionsDispatcher, IMyAppActionsDispatcherTrait, m_Player, Player,
e_Highscore
};
use pixelaw::core::actions::{actions, IActionsDispatcher, IActionsDispatcherTrait};

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::models::registry::{App, AppName, CoreActionsAddress};
use pixelaw::core::test_helpers::{
update_test_world, 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_rgba, decode_rgba, Direction, Position, DefaultParameters
};
use starknet::class_hash::Felt252TryIntoClassHash;

use zeroable::Zeroable;

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());

fn deploy_app(ref world: WorldStorage) -> IMyAppActionsDispatcher {
let ndef = NamespaceDef {
namespace: "pixelaw", resources: [
TestResource::Model(m_Player::TEST_CLASS_HASH),
TestResource::Event(e_Highscore::TEST_CLASS_HASH),
TestResource::Contract(myapp_actions::TEST_CLASS_HASH),
].span()
};

let cdefs: Span<ContractDef> = [
ContractDefTrait::new(@"pixelaw", @"myapp_actions")
.with_writer_of([dojo::utils::bytearray_hash(@"pixelaw")].span())
].span();

update_test_world(ref world, [ndef].span());

world.sync_perms_and_inits(cdefs);

let (myapp_actions_address, _) = world.dns(@"myapp_actions").unwrap();
IMyAppActionsDispatcher { contract_address: myapp_actions_address }
}

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

// Deploy MyApp actions
let myapp_actions = deploy_app(world);
let myapp_actions = deploy_app(ref world);

myapp_actions.init();

Expand All @@ -55,7 +76,7 @@ mod tests {
},
);

let pixel_1_1 = get!(world, (1, 1), (Pixel));
let pixel_1_1: Pixel = world.read_model((1, 1));
assert(pixel_1_1.color == color, 'should be the color');

'Passed test'.print();
Expand Down

0 comments on commit 4de322d

Please sign in to comment.