Skip to content

Commit

Permalink
chore(torii): types test proj
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Aug 22, 2023
1 parent bec0ca2 commit a88a446
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/torii/graphql/src/tests/types-test/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
cairo-version = "2.1.1"
name = "types_test"
version = "0.1.0"

[cairo]
sierra-replace-ids = true

[dependencies]
dojo = { path = "../../../../../dojo-core" }

[[target.dojo]]

[tool.dojo]
initializer_class_hash = "0xbeef"

[tool.dojo.env]
rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
account_address = "0x3ee9e18edc71a6df30ac3aca2e0b02a198fbce19b7480a63a0d71cbd76652e0"
private_key = "0x300001800000000300000180000000000030000000000003006001800006600"
# world_address = "0x789c94ef39aeebc7f8c4c4633030faefb8bee454e358ae53d06ced36136d7d6"
# keystore_password = "password"
# keystore_path = "../keystore.json"
18 changes: 18 additions & 0 deletions crates/torii/graphql/src/tests/types-test/src/components.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use array::ArrayTrait;
use starknet::{ContractAddress, ClassHash};

#[derive(Component, Copy, Drop, Serde, SerdeLen)]
struct Record {
#[key]
record_id: u32,
type_u8: u8,
type_u16: u16,
type_u32: u32,
type_u64: u64,
type_u128: u128,
type_u256: u256,
type_bool: bool,
type_felt: felt252,
type_class_hash: ClassHash,
type_contract_address: ContractAddress,
}
2 changes: 2 additions & 0 deletions crates/torii/graphql/src/tests/types-test/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod components;
mod systems;
43 changes: 43 additions & 0 deletions crates/torii/graphql/src/tests/types-test/src/systems.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#[system]
mod spawn {
use array::ArrayTrait;
use box::BoxTrait;
use option::OptionTrait;
use traits::{Into, TryInto};
use starknet::class_hash::{Felt252TryIntoClassHash};

use dojo::world::Context;
use types_test::components::Record;

fn execute(ctx: Context, num_records: u8) {
let mut curr_record = 0;
loop {
if curr_record == num_records {
break();
}
curr_record = curr_record + 1;

let record_id = ctx.world.uuid();
let curr_felt: felt252 = curr_record.into();
set !(
ctx.world,
(
Record {
record_id,
type_u8: curr_record.into(),
type_u16: curr_record.into(),
type_u32: curr_record.into(),
type_u64: curr_record.into(),
type_u128: curr_record.into(),
type_u256: curr_record.into(),
type_bool: if curr_record % 2 == 0 { true } else { false },
type_felt: curr_felt,
type_class_hash: curr_felt.try_into().unwrap(),
type_contract_address: curr_felt.try_into().unwrap(),
}
)
);
};
return ();
}
}

0 comments on commit a88a446

Please sign in to comment.