Skip to content

Commit

Permalink
feat: add auth script
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Jan 29, 2024
1 parent 61fc919 commit d4c7ec1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 63 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: CI
on:
push:
pull_request:
env:
DEPLOY_RPC_URL: https://katana.0xmssp.xyz
TARGET: mssp

jobs:
sozo-test:
Expand All @@ -11,10 +14,14 @@ jobs:
- uses: actions/checkout@v3
- run: curl -L https://install.dojoengine.org | bash
- run: /home/runner/.config/.dojo/bin/dojoup
- run: /home/runner/.config/.dojo/bin/sozo build
- run: /home/runner/.config/.dojo/bin/sozo test
- run: /home/runner/.config/.dojo/bin/sozo --profile dev migrate
- run: echo $PATH
- run: cp /home/runner/.config/.dojo/bin/sozo /usr/local/bin/sozo
- run: sozo build
- run: sozo test
- run: sozo --profile $TARGET migrate
- run: ls target
- uses: actions/upload-artifact@v4
with:
name: manifest.json
path: target/dev/manifest.json
path: target/$TARGET/manifest.json
- run: bash scripts/default_auth.sh
3 changes: 2 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ rpc_url = "http://localhost:5050/"
account_address = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
private_key = "0x1800000000300000180000000000030000000000003006001800006600"

[profile.dev.tool.dojo.env]
[profile.mssp.tool.dojo.env]
rpc_url = "https://katana.0xmssp.xyz/"
# Default account for katana with seed = 0
account_address = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
private_key = "0x1800000000300000180000000000030000000000003006001800006600"


[tool.dojo.world]
name = "Dojo starter"
description = "The official Dojo Starter guide, the quickest and most streamlined way to get your Dojo Autonomous World up and running. This guide will assist you with the initial setup, from cloning the repository to deploying your world."
Expand Down
22 changes: 17 additions & 5 deletions scripts/default_auth.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#!/bin/bash
set -euo pipefail
set -xeuo pipefail
pushd $(dirname "$0")/..

export RPC_URL="http://localhost:5050";
if [ -z "$DEPLOY_RPC_URL" ]
then
export RPC_URL="$DEPLOY_RPC_URL";
else
export RPC_URL="http://localhost:5050";
fi

export WORLD_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.world.address')
if [ -z "$TARGET_NAME"]
then
pass;
else
export TARGET_NAME="dev";
fi

export ACTIONS_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.contracts[] | select(.name == "dojo_starter::systems::actions::actions" ).address')
export WORLD_ADDRESS=$(cat ./target/$TARGET_NAME/manifest.json | jq -r '.world.address')

export ACTIONS_ADDRESS=$(cat ./target/$TARGET_NAME/manifest.json | jq -r '.contracts[] | select(.name == "kingdom_lord::systems::actions::actions" ).address')

echo "---------------------------------------------------------------------------"
echo world : $WORLD_ADDRESS
Expand All @@ -15,7 +27,7 @@ echo actions : $ACTIONS_ADDRESS
echo "---------------------------------------------------------------------------"

# enable system -> component authorizations
COMPONENTS=("Position" "Moves" )
COMPONENTS=("ResourceField" "Warehouse" "Barn")

for component in ${COMPONENTS[@]}; do
sozo auth writer $component $ACTIONS_ADDRESS --world $WORLD_ADDRESS --rpc-url $RPC_URL
Expand Down
83 changes: 30 additions & 53 deletions src/tests/test_world.cairo
Original file line number Diff line number Diff line change
@@ -1,62 +1,39 @@
// #[cfg(test)]
// mod tests {
// use starknet::class_hash::Felt252TryIntoClassHash;
#[cfg(test)]
mod tests {
use starknet::class_hash::Felt252TryIntoClassHash;

// // import world dispatcher
// use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
// import world dispatcher
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};

// // import test utils
// use dojo::test_utils::{spawn_test_world, deploy_contract};
// import test utils
use dojo::test_utils::{spawn_test_world, deploy_contract};

// // import test utils
// use dojo_starter::{
// systems::{actions::{actions, IActionsDispatcher, IActionsDispatcherTrait}},
// models::{position::{Position, Vec2, position}, moves::{Moves, Direction, moves}}
// };
use kingdom_lord::tests::utils::setup_world;
use kingdom_lord::models::{
resource_field::{ResourceField, resource_field}, warehouse::{Warehouse, warehouse},
barn::{Barn, barn}
};

use kingdom_lord::systems::actions::{actions, actions::{ResourceActionsDispatcher, ResourceActionsDispatcherTrait, AdminActionsDispatcher, AdminActions}};
#[test]
#[available_gas(30000000)]
fn test_mine() {
// caller
let caller = starknet::contract_address_const::<0x0>();

// #[test]
// #[available_gas(30000000)]
// fn test_move() {
// // caller
// let caller = starknet::contract_address_const::<0x0>();
// models
let mut models = array![resource_field::TEST_CLASS_HASH, warehouse::TEST_CLASS_HASH, barn::TEST_CLASS_HASH];

// // models
// let mut models = array![position::TEST_CLASS_HASH, moves::TEST_CLASS_HASH];
// deploy world with models
let world = spawn_test_world(models);

// // deploy world with models
// let world = spawn_test_world(models);
// deploy systems contract
let contract_address = world
.deploy_contract('salt', actions::TEST_CLASS_HASH.try_into().unwrap());
let actions_system = ResourceActionsDispatcher { contract_address };

// // deploy systems contract
// let contract_address = world
// .deploy_contract('salt', actions::TEST_CLASS_HASH.try_into().unwrap());
// let actions_system = IActionsDispatcher { contract_address };
// call spawn()
actions_system.spawn();

// // call spawn()
// actions_system.spawn();

// // call move with direction right
// actions_system.move(Direction::Right);

// // Check world state
// let moves = get!(world, caller, Moves);

// // casting right direction
// let right_dir_felt: felt252 = Direction::Right.into();

// // check moves
// assert(moves.remaining == 99, 'moves is wrong');

// // check last direction
// assert(moves.last_direction.into() == right_dir_felt, 'last direction is wrong');

// // get new_position
// let new_position = get!(world, caller, Position);

// // check new position x
// assert(new_position.vec.x == 11, 'position x is wrong');

// // check new position y
// assert(new_position.vec.y == 10, 'position y is wrong');
// }
// }
}
}

0 comments on commit d4c7ec1

Please sign in to comment.